首先貼一下官網的教程:使用通用二進制文件在Unix / Linux上安裝MySQL
下載安裝包
(下載地址 需要其他版本自行官網下載)
執行腳本
shell> groupadd mysql
shell> useradd -r -g mysql -s /bin/false mysql
shell> cd /usr/local
shell> tar zxvf /path/to/mysql-VERSION-OS.tar.gz
shell> ln -s full-path-to-mysql-VERSION-OS mysql
shell> cd mysql
shell> mkdir mysql-files
shell> chown mysql:mysql mysql-files
shell> chmod 750 mysql-files
shell> bin/mysqld --initialize --user=mysql
shell> bin/mysql_ssl_rsa_setup
shell> bin/mysqld_safe --user=mysql &
# Next command is optional
shell> cp support-files/mysql.server /etc/init.d/mysql.server
執行bin/mysqld --initialize --user=mysql 生成的隨機密碼,之後第一次登陸要用
這時候直接運行可能會報錯,需要重啓一下服務
shell> service mysql restart
會提示你
這時候執行
shell> systemctl deamon-reload
shell> service mysql restart
修改密碼
shell> cd mysql/bin
shell> ./mysql -uroot -p
enter password: (輸入剛剛生成的密碼)
mysql> set password for root@localhost=password('new password')
以上就是所有步驟,其他安裝方式請官網查看 官網教程