1、解壓mysql-8.0.13-linux-glibc2.12-x86_64.tar.xz到一個文件夾中,隨便一個文件夾,后面需要轉移的。
# tar -xvf mysql-8.0.13-linux-glibc2.12-x86_64.tar.xz
如果報如下錯誤,請安裝組件
[root@iZ8vbf0nw945emer2xmpdhZ soft]# tar -xvf mysql-8.0.13-linux-glibc2.12-x86_64.tar.xz
tar (child): xz: Cannot exec: No such file or directory
tar (child): Error is not recoverable: exiting now
tar: Child returned status 2
tar: Error is not recoverable: exiting now
[root@iZ8vbf0nw945emer2xmpdhZ soft]# yum install -y xz
2、將解壓的文件重命名mysql,並移動到/usr/local目錄下
# mv mysql-8.0.13-linux-glibc2.12-x86_64 mysql # mv mysql /usr/local/

3、進入到/usr/local目錄下,創建用戶和用戶組並授權
# cd /usr/local/ # groupadd mysql # useradd -r -g mysql mysql # cd mysql/ #注意:進入mysql文件下授權所有的文件 # chown -R mysql:mysql ./

4、再/usr/local/mysql目錄下,創建data文件夾
# mkdir data

5、初始化數據庫,並會自動生成隨機密碼,記下等下登陸要用
# bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

要是初始化報這個錯誤:
請安裝:yum -y install libaio 和yum -y install numactl就可以了
6、修改/usr/local/mysql當前目錄得用戶
# chown -R root:root ./ # chown -R mysql:mysql data

7、# cp support-files/my-default.cnf /etc/my.cnf
復制過去,其實也就是空白頁,一開始沒有my-default.cnf這個文件,可以用# touch my-default.cnf命令創建一個,並配置權限 # chmod 777 ./my-default.cnf
# cd support-files/ # touch my-default.cnf # chmod 777 ./my-default.cnf # cd ../ # cp support-files/my-default.cnf /etc/my.cnf

8、配置my.cnf
# vim /etc/my.cnf
[mysqld] # Remove leading # and set to the amount of RAM for the most important data # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%. # innodb_buffer_pool_size = 128M # Remove leading # to turn on a very important data integrity option: logging # changes to the binary log between backups. # log_bin # These are commonly set, remove the # and set as required. basedir = /usr/local/mysql datadir = /usr/local/mysql/data socket = /tmp/mysql.sock log-error = /usr/local/mysql/data/error.log pid-file = /usr/local/mysql/data/mysql.pid tmpdir = /tmp port = 3306 #lower_case_table_names = 1 # server_id = ..... # socket = ..... #lower_case_table_names = 1 max_allowed_packet=32M default-authentication-plugin = mysql_native_password #lower_case_file_system = on #lower_case_table_names = 1 log_bin_trust_function_creators = ON # Remove leading # to set options mainly useful for reporting servers. # The server defaults are faster for transactions and fast SELECTs. # Adjust sizes as needed, experiment to find the optimal values. # join_buffer_size = 128M # sort_buffer_size = 2M # read_rnd_buffer_size = 2M sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
如果后期mysql運行報錯,可以直接到log-error = /usr/local/mysql/data/error.log目錄下直接查看錯誤日志
命令:cat /usr/local/mysql/data/error.log
9、開機自啟,進入/usr/local/mysql/support-files進行設置
# cd support-files/ # cp mysql.server /etc/init.d/mysql # chmod +x /etc/init.d/mysql

10、注冊服務
# chkconfig --add mysql
如果命令沒有,在需要處理chkconfig
# rpm -aq |grep chkconfig # export PATH=/sbin:$PATH # chkconfig # echo $PATH # PATH="$PATH":/sbin # echo $PATH

11、查看是否成功
12、etc/ld.so.conf要配置路徑,不然報錯
# vim /etc/ld.so.conf 添加如下內容: /usr/local/mysql/lib

13、配置環境變量
# vim /etc/profile # source /etc/profile 添加如下內容: #MYSQL ENVIRONMENT export PATH=$PATH:/usr/local/mysql/bin:/usr/local/mysql/lib

14、登陸,這里輸入上面第6步隨機生成得密碼,細心點輸入,沒有顯示的,登陸成功如圖所示
你可能因為丟失套接字文件而不能連接(如上截圖錯誤),你可以簡單地通過重啟服務器重新創建得到它。因為服務器在啟動時重新創建它。
15、開啟Navicat遠程連接
mysql> use mysql; #如果報以下該錯誤 ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement. mysql> ALTER USER USER() IDENTIFIED BY 'root'; #解決方式
然后繼續下面操作,沒有錯誤也是繼續下面操作
# mysql -uroot -p #進入數據庫 > use mysql;#進入數據庫 > select host, user, authentication_string, plugin from user;#查看用戶信息 > GRANT ALL ON *.* TO 'root'@'%';#授權root用戶可以遠程登陸 > flush privileges;#立即生效 > ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'Kuaigui2019!';#修改root用戶密碼 > FLUSH PRIVILEGES;#立即生效 > exit;#退出 # service mysql restart#重啟mysql服務
16、navicat連接成功