linux下安裝mysql8.0.x步驟

1.下載mysqlphp

mysql官網:https://dev.mysql.com/downloads/mysql/html

將下載的mysql上傳打linuxmysql

2.解壓並重命名linux

[root@rsyncClient local]# tar -zxvf mysql-8.0.18-el7-x86_64.tar.gz -C /usr/local/ [root@rsyncClient local]# mv mysql-8.0.18-el7-x86_64/ mysql

3.在mysql根目錄下建立data目錄,存放數據sql

[root@rsyncClientopt]# cd /usr/local/mysql/ [root@rsyncClient mysql]# mkdir data

4.建立mysql用戶組和mysql用戶數據庫

[root@rsyncClient local]# groupadd mysql [root@rsyncClient local]# useradd -g mysql mysql

5.改變mysql目錄權限vim

[root@rsyncClient local]# chown -R mysql.mysql /usr/local/mysql/

6.初始化數據庫bash

[root@rsyncClient mysql]# bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql 
--datadir=/usr/local/mysql/data

7.配置mysqlsocket

在mysql/support-files建立文件my-default.cnftcp

[root@rsyncClient support-files]# cd /usr/local/mysql/support-files/ [root@rsyncClient support-files]# touch my-default.cnf

複製配置文件到/etc/my.cnf

[root@rsyncClient support-files]# cp -a ./my-default.cnf /etc/my.cnf cp: overwrite ‘/etc/my.cnf’? y

編輯my.cnf

[client] port=3306 socket=/tmp/mysql.sock [mysqld] port=3306 user=mysql socket=/tmp/mysql.sock basedir=/usr/local/mysql datadir=/usr/local/mysql/data

8.配置環境變量

編輯 / etc/profile 文件

[root@rsyncClient mysql]# vim /etc/profile #配置mysql環境變量 PATH=/data/mysql/bin:/data/mysql/lib:$PATH export PATH
#讓其生效 [root@rsyncClient mysql]# source
/etc/profile
#看環境變量是否生效 [root@rsyncClient mysql]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin

9.啓動mysql

[root@rsyncClient mysql]# systemctl start mysqld

啓動失敗報錯1:

Job for mysql.service failed because the control process exited with error code. See "systemctl status mysql.service" and "journalctl -xe" for details.

解決方案:

[root@rsyncClient ~]# chown mysql:mysql -R /usr/local/mysql/

啓動失敗報錯2:

[root@rsyncClient mysql]# service mysql start /etc/init.d/mysql: ./bin/my_print_defaults: /lib/ld-linux.so.2: bad ELF interpreter: No such file or 
directory Starting MySQL. ERROR
! The server quit without
updating PID file (/var/lib/mysql/rsyncClient.pid).
去這個目錄下面查看 cat/usr/local/mysql/data/rsyncClient.err錯誤,對應的的解決,這裏錯誤是由於my.conf配置錯誤

 啓動失敗報錯3:

mysql: error while loading shared libraries: libncurses.so.5: cannot open shared object file:
No such file or directory [root@rsyncClient init.d]# yum install libncurses.so.
5
以這個爲例,若是缺乏這樣依賴,直接用yum安裝

啓動失敗報錯4:

[root@rsyncClient data]# mysql -uroot -p Enter password: ERROR 2059 (HY000): Authentication plugin 'caching_sha2_password' cannot be loaded: 
/usr/lib/mysql/plugin/caching_sha2_password.so: cannot open shared object file: No such file or directory
身份驗證插件不能加載

解決辦法:

[root@rsyncClient lib]# vim /etc/my.cnf
在這個[mysqld]下添加一行:
default_authentication_plugin=mysql_native_password
若是忘記了密碼在加上:
skip-grant-tables(跳過密碼驗證)等設置了密碼就去掉

10 使用systemctl命令啓動關閉mysql服務

啓動mysql服務:
 
#systemctl start mysqld.service
 
中止mysql服務
 
#systemctl stop mysqld.service
 
重啓mysql服務
 
#systemctl restart mysqld.service
 
查看mysql服務當前狀態
 
#systemctl status mysqld.service
 
設置mysql服務開機自啓動
 
#systemctl enable mysqld.service
 
中止mysql服務開機自啓動
 
#systemctl disable mysqld.service

11.mysql的基本操做

# 使用mysql客戶端鏈接mysql
>/usr/local/mysql/bin/mysql -u root -p password
修改mysql的默認初始化密碼
> alter user 'root'@'localhost' identified by 'root';
# 建立用戶 CREATE USER '用戶名稱'@'主機名稱' INDENTIFIED BY '用戶密碼'
> create user 'yehui'@'localhost' identified by 'yehui';
#給全部遠程登陸的進行受權,此方式已經報錯了
> grant all privileges on *.*  to  'root'@'%'  identified by 'root'  with grant option;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'identified by 'root'  with grant option' at line 1
# 修改root用戶能夠遠程鏈接
> update mysql.user set host='%' where user='root';
 
# 授予權限 grant 權限 on 數據庫.表 to '用戶名'@'登陸主機' [INDENTIFIED BY '用戶密碼'];
> grant replication slave on *.* to 'yehui'@'localhost';
#刷新
>flush privileges;

 12.防火牆問題

[root@rsyncClient data]# firewall-cmd --permanent --zone=public --add-port=3306/tcp #容許訪問 success [root@rsyncClient data]# firewall-cmd --reload #從新加載 success

[root@rsyncClient data]# firewall-cmd --permanent --zone=public --query-port=3306/tcp  #查看是否開通訪問權限
yes   

相關文章
相關標籤/搜索