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;