1. 程式人生 > 資料庫 >centOS安裝mysql5.7詳細教程

centOS安裝mysql5.7詳細教程

本文為大家分享了centOS下安裝mysql5.7詳細步驟,供大家參考,具體內容如下

第一步:

第一句檢測系統是否自帶安裝mysql,若有執行第二句刪除系統自帶的mysql及其依賴。

yum list installed | grep mysql
yum -y remove mysql-libs.x86_64

第二步:

給CentOS新增rpm源,並且選擇較新的源,下面程式碼逐句執行

wget dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm
yum localinstall mysql-community-release-el6-5.noarch.rpm
yum repolist all | grep mysql
yum-config-manager --disable mysql55-community
yum-config-manager --disable mysql56-community
yum-config-manager --enable mysql57-community-dmr
yum repolist enabled | grep mysql

第三步:

安裝mysql 伺服器

yum install mysql-community-server

第四步:

service mysqld start

第五步:

檢視mysql是否自啟動,並且設定開啟自啟動

chkconfig --list | grep mysqld
chkconfig mysqld on

第六步:

這一步很重要!!!

不知道從mysql哪個版本開始,mysql的root預設密碼就不為空了,在安裝的過程中預設密碼儲存在安裝日誌中了。我們要通過安裝日誌找到預設密碼,用預設密碼登陸mysql成功後會強行讓你修改密碼,修改的密碼還要夠複雜(複合mysql預設的密碼策略)才能修改成功,一般帶大小寫字母特殊字元和數字超過8個字元就可以。

首先找到安裝日誌

find / -name mysqld.log

然後發現該日誌檔案路徑在 /var/log/mysqld.log。然後用下面命令開啟,按‘i'鍵上翻

vim /var/log/mysqld.log

上圖紅色地方就是root密碼所在地

第七步:

mysql安全設定

mysql_secure_installation

輸入上面命令進行下面步驟

SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MySQL to secure it,we'll need the current
password for the root user. If you've just installed MySQL,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 MySQL
root user without the proper authorisation.
Set root password? [Y/n] <– 是否設定root使用者密碼,輸入y並回車或直接回車
New password: <– 設定root使用者的密碼
Re-enter new password: <– 再輸入一次你設定的密碼
Password updated successfully!
Reloading privilege tables..
… Success!
By default,a MySQL installation has an anonymous user,allowing anyone
to log into MySQL 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] <– 是否刪除匿名使用者,生產環境建議刪除,所以直接回車
… 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] <–是否禁止root遠端登入,根據自己的需求選擇Y/n並回車,建議禁止
… Success!
By default,MySQL 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] <– 是否刪除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] <– 是否重新載入許可權表,直接回車
… Success!
Cleaning up…
All done! If you've completed all of the above steps,your MySQL
installation should now be secure.
Thanks for using MySQL!
[root@server1 ~]#

第八步:

可選步驟,原來Linux下的MySQL預設是區分表名大小寫的,通過如下設定,可以讓MySQL不區分表名大小寫:
1、用root登入,修改 /etc/my.cnf;
2、在[mysqld]節點下,加入一行: lower_case_table_names=1
3、重啟MySQL即可; service mysqld restart

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支援我們。