安裝環境:RedHat6.5
第一步:下載下傳
下載下傳MySQL5.7:http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.12-1.el6.x86_64.rpm-bundle.tar
第二步:安裝
安裝前檢查伺服器是否已安裝MySQL,如已安裝則将其解除安裝:
[[email protected] tmp]# rpm -qa|grep mysql
mysql-libs-5.1.71-1.el6.x86_64
[[email protected] tmp]# rpm -e --nodeps mysql-libs-5.1.71-1.el6.x86_64 //解除安裝
将下載下傳的檔案進行解壓:
[[email protected] tmp]# tar -xf mysql-5.7.12-1.el6.x86_64.rpm-bundle.tar
按順序依次安裝:
1. rpm -ivh mysql-community-common-5.7.12-1.el6.x86_64.rpm
2. rpm -ivh mysql-community-libs-5.7.12-1.el6.x86_64.rpm
3. rpm -ivh mysql-community-devel-5.7.12-1.el6.x86_64.rpm
4. rpm -ivh mysql-community-client-5.7.12-1.el6.x86_64.rpm
5. rpm -ivh mysql-community-server-5.7.12-1.el6.x86_64.rpm
不出意外,MySQL應該已經安裝成功。
第三步:環境變量設定
啟動MySQL:service mysqld start
這一步如果出錯,mysql初始化失敗,有可能是端口占用問題,最簡單的方法是重新開機伺服器。
登入:mysql -u root -p,初次登入密碼為空,直接回車:
為什麼會出現這個錯誤,原因是因為MySQL5.7中的mysql.user 表中沒有Password字段,是以要以安全方式登入,然後修改密碼。
解決方法如下:
修改MySQL配置檔案:vim /etc/my.cnf,在檔案末尾加上:skip-grant-tables,儲存後重新開機MySQL服務:service mysqld restart,然後重新登入。
修改密碼,使用者密碼是在名為mysql的database下面:
依次執行以下指令:
mysql> use mysql
mysql> update user set password_expired='N' where user='root’;
mysql> update user set authentication_string=password('123456') where user=‘root’;
mysql> flush privileges;
注意:一定要将my.cnf配置檔案之前加的跳過密碼檢測内容去掉,重新開機服務;
其他:
編碼設定:vim /etc/my.cnf,檔案末尾加上編碼内容default-character-set=utf8
允許遠端通路MySQL:
賦予任何主機通路資料的權限
mysql>grant all privileges on *.* to ‘root’@’%’with grant option;
會報錯:ERROR 1133 (42000): Can’t find any matching row in the user table
其實如果事先在mysql.user表中存在root使用者就正常了,或,将這句末尾加上identified by ‘密碼’ 也就正常了。如下面的指令行
mysql>grant all privileges on *.* to ‘root’@’%’identified by ‘123456’ with grant option;
例如:grant all privileges on *.* to ‘root’@'192.168.128.1' identified by ‘123456’ with grant option;
更改密碼政策:
mysql> set global validate_password_length=0; --更改密碼長度
mysql> set global validate_password_policy=0; --更改密碼政策為LOW