【MySQL數據庫】CentOS 7 通過 yum 安裝 MariaDB

虛擬機中我們可能會使用到MySQL數據庫,那麼如何安裝環境呢~

小編廢了九牛二虎之力安裝好了,所以寫出來給你們~

不過切記!下面的一切操作要在root下完成吖

1.安裝 mariadb 服務

# yum install -y mariadb-server

不過經過測試第一個步驟已經順便安裝好了2,3,如果你執行完第一個步驟,也是如圖所示,那麼可以跳過2,3啦~

2.安裝 mariadb 命令行客戶端

# yum install -y mariadb

3.安裝 mariadb C library

# yum install -y mariadb-libs

4.安裝 mariadb 開發包

# yum install -y mariadb-devel

5.更改 /etc/my.cnf.d 文件

# cd /etc/my.cnf.d

裏面有三個文件 

①編輯client.cnf文件,[client] 下加一行配置

default-character-set=utf8

最終內容:

②編輯mysql-clients.cnf文件,[mysql] 下加一行配置

default-character-set=utf8

最終內容:

③編輯server.cnf 文件,[mysqld] 下加配置

collation-server = utf8_general_ci

init-connect='SET NAMES utf8'

character-set-server = utf8

sql-mode = TRADITIONAL

最終內容:

6.啓動服務

# systemctl start mariadb

7.設置服務開啓自啓動

# systemctl enable mariadb

8.查看服務狀態

# systemctl enable mariadb

9.測試連接----使用命令行客戶端嘗試連接

# mysql -uroot

如圖所示就是連接成功 

10.查看 mariadb 版本號

11.查看字符集配置

 

使用完成用Ctrl+D或者quit退出!

 

12.設置密碼

[root@bogon my.cnf.d ~]# mysql_secure_installation 
/usr/bin/mysql_secure_installation: line 379: find_mysql_client: command not found
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none): 當前數據庫密碼爲空,直接敲擊回車。
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.
Set root password? [Y/n] y
New password: 輸入要爲root用戶設置的數據庫密碼。
Re-enter new password: 重複再輸入一次密碼。
Password updated successfully!
Reloading privilege tables..
 ... Success!
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] y(刪除匿名帳號)
 ... Success!
Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] y(禁止root用戶從遠程登錄)
 ... Success!
By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] y(刪除test數據庫並取消對其的訪問權限)
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] y(刷新授權表,讓初始化後的設定立即生效)
 ... Success!
Cleaning up...
All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!

 

 

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章