MySQL5.7 增加用戶,新建數(shù)據(jù)庫,授權(quán),遠程訪問
1.安裝yum repo
wget https://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
然后進行repo的安裝
rpm -ivh mysql57-community-release-el7-9.noarch.rpm
2.安裝MySQL5.7(如果遇到錯誤,參考2.1,2.2)
使用yum命令
yum install mysql-server
2.1可能會遇到報錯
安裝過程中可能出現(xiàn)的報錯
mariadb101u-common conflicts with mysql-community-common-5.7.24-1.el7.x86_64
mariadb101u-config conflicts with mysql-community-server-5.7.24-1.el7.x86_64

沖突.png
上面的mariadb101u和mysql沖突了,那么卸載掉即可,注意看一共有幾個errors
2.2處理卸載沖突的軟件
卸載的版本要和Erros地方對應起來,例如
rpm -e mariadb101u-config-10.1.35-1.ius.centos7.x86_64 --nodeps
3.設置無密碼啟動
- 編輯配置MySQL文件
vim /etc/my.cnf
- 在配置文件最后加入無密碼啟動的配置
skip-grant-tables
- 重啟MySQL服務
systemctl restart mysqld.service
或者 systemctl restart mysqld
service restart mysql可能是不行的
4.修改MySQL root密碼
- 無密碼進入MySQL
mysql -uroot;
- 修改root密碼,例如:
use mysql;
update user set authentication_string = password('root'), password_expired = 'N', password_last_changed = now() where user = 'root';
需要注意的是,MySQL5.7中,已經(jīng)不再用password這個字段.而是authentication_string
可以通過查看mysql庫中的user表看到:

mysql庫user表的表結(jié)構(gòu)
5.去掉無密碼啟動的配置
- 退出MySQL
exit;
- 編輯MySQL配置文件,去掉第五步中的
skip-grant-tables
- 重啟MySQL
systemctl restart mysqld.service
- 用密碼登錄MySQL
mysql -uroot -p

搞定~~.png