1.下載mysql
https://dev.mysql.com/downloads/mysql/
~] cd /usr/local
~] wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.18-linux-glibc2.12-x86_64.tar.xz
~] tar xvf mysql-8.0.18-linux-glibc2.12-x86_64.tar.xz
~] mv mysql-8.0.18-linux-glibc2.12-x86_64 mysql
~] rm -rf mysql-8.0.18-linux-glibc2.12-x86_64.tar.xz
----- 新建mysql用戶、組及目錄、數據倉庫目錄
~] groupadd mysql
~] useradd -r -s /sbin/nologin -g mysql mysql -d /usr/local/mysql
~] cd /usr/local/mysql
~] chown -R mysql .
~] chgrp -R mysql .
~] mkdir /data/mysql
~] chown -R mysql /data/mysql
----- 開始配置參數
~] bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
If Error:
bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
檢查該鏈接庫文件有沒有安裝使用:
~] rpm -qa|grep libaio
命令運行後系統中無該鏈接庫文件,安裝
~] yum install libaio-devel.x86_64
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
2019-12-27T03:12:51.138272Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: r7l<MlxQ9+LJ
~] bin/mysql_ssl_rsa_setup --datadir=/data/mysql
-- 要先記住上面返回的臨時密碼哈:r7l<MlxQ9+LJ
----- 修改系統配置文件
~] vi /etc/my.cnf
[mysqld]
basedir=/usr/local/mysql
datadir=/data/mysql
socket=/tmp/mysql.sock
----- 添加Mysql到系統服務
~] cp -a ./support-files/mysql.server /etc/init.d/mysql
~] chmod +x /etc/init.d/mysql
~] chkconfig --add mysql
~] chkconfig --list mysql # 檢查是否生效
---------- 啓動Mysql
~] service mysql start
Starting MySQL... [ OK ]
----- 軟鏈個bin/mysql
~] ln -s /usr/local/mysql/bin/mysql /usr/bin/
----- 登陸
~] mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.18
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
----- 修改密碼:
~> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'ABCD!!1234a';
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
If Error:
Starting MySQL...... mysqld_safe error: log-error set to '/var/log/mari.....
~] mkdir /var/log/mariadb/ && touch /var/log/mariadb/mariadb.log
~] chown -R mysql:mysql /var/log/mariadb/
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
啓動 : service mysql start
查看 : service mysql status
重啓 : service mysql reload / restart
停止 : service mysql stop
----- 配置外部連接
my.cnf 下增加 mysqld
default_authentication_plugin=mysql_native_password
--- 設置root賬戶的host地址
~> use mysql
~> update user set host ='%' where user='root';
##~> ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'ABCD!!1234a';
~> FLUSH PRIVILEGES;