在MySQL官網中下載YUM源rpm安裝包:http://dev.mysql.com/downloads/repo/yum/html
一、下載mysql源安裝包
wget http://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm
二、安裝mysql源
yum localinstall mysql80-community-release-el7-1.noarch.rpm
三、檢查mysql源是否安裝成功
yum repolist enabled | grep "mysql.*-community.*"
mysql
看到上圖所示表示安裝成功。
四、選擇想要安裝的版本
vim /etc/yum.repos.d/mysql-community.repolinux
想要安裝哪一個版本的mysql 就把哪一個版本的enabled的值設爲1(默認他設置的是當前最高版本),若是修改版本別忘記把默認的值改爲0ios
五、安裝MySQL
yum install mysql-community-serversql
這步看網速,須要下載好多東西,最後會提示Complete!
六、啓動MySQL服務vim
systemctl start mysqld /service mysqld startthis
須要小等一會.net
七、查看MySQL的啓動狀態3d
systemctl status mysqldrest
啓動成功!
八、設置開機啓動
systemctl enable mysqld
systemctl daemon-reload
九、修改登陸密碼(root)
mysql安裝完成以後,在/var/log/mysqld.log文件中給root生成了一個默認密碼。經過下面的方式找到root默認密碼,而後登陸mysql進行修改
grep 'temporary password' /var/log/mysqld.log
若是文件爲空直接
root 密碼爲空的時候配置文件中配置這句:
mysql 配置文件目錄:/etc/my.cnf
skip-grant-tables
配置以後重啓服務纔會生效
service mysqld restart
十、登陸mysql
mysql -uroot
無密碼就能夠進去
修改密碼
ALTER USER 'root'@'localhost' IDENTIFIED BY '111111!'; 或者 set password for 'root'@'localhost'=password('111111!');
若是:ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
輸入下面語句(目的是刷新權限)
flush privileges;
Query OK, 0 rows affected (0.14 sec)
ALTER USER 'root'@'localhost' IDENTIFIED BY '111111!'; 或者 set password for 'root'@'localhost'=password('111111!');
若是:ERROR 3009 (HY000): Column count of mysql.user is wrong. Expected 45, found 42. Created with MySQL 50556, now running 50722. Please use mysql_upgrade to fix this error.
退出去
mysql_upgrade -u root
無密碼
出現一系列這東西,不要緊。
登陸mysql
mysql -uroot
無密碼能夠進去
修改密碼
ALTER USER 'root'@'localhost' IDENTIFIED BY '111111!'; 或者 set password for 'root'@'localhost'=password('111111!');
註釋掉skip-grant-tables
重啓服務
service mysqld restart
此次退出去再試試新密碼好很差用
最後感謝各位前輩的技術分享:
https://www.linuxidc.com/Linux/2016-09/135288.htm;
https://blog.csdn.net/qq_33350186/article/details/72528810;
https://www.cnblogs.com/iosdev/archive/2013/07/15/3190431.html;