检查是否有mariadb
c
rpm -qa|grep mariadb
rpm -e --nodeps mariadb-server
安装mysql-8.0.31-el7-x86_64.tar.gz包
安装mysql-8.0.31-el7-x86_64.tar.gz包
c
cd data
tar -xvf mysql-8.0.31-el7-x86_64.tar.gz
mv mysql-8.0.31-el7-x86_64 mysql
依赖安装
报错解决,安装依赖 yum install -y libaio
还有报错,安装依赖 yum -y install numactl
修改mysql配置
vi /etc/my.cnf 覆盖以下全部内容,注意格式
c
[client]
port=3306
socket=/data/tmp/mysql/mysql.sock
[mysqld]
port=3306
user=mysql
socket=/data/tmp/mysql/mysql.sock
basedir=/data/mysql
datadir=/data/mysql/data
log-error=error.log
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
max_connections = 4096
transaction_isolation = READ-COMMITTED
character-set-server = utf8mb4
#collation-server = utf8mb4_general_ci
collation-server = utf8mb4_bin
lower_case_table_names = 1
#生产环境注释
skip-grant-tables
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
[mysqld_safe]
log-error=/data/tmp/mysql/log/mysqld.log
pid-file=/data/tmp/mysql/run/mysqld/mysqld.pid
#log-error=/var/log/mysqld.log
#pid-file=/var/run/mysqld/mysqld.pid
#my.ini配置文件中更改允许的最大错误连接数
max_connect_errors = 8000
初始化mysql配置
groupadd mysql
$> useradd -r -g mysql -s /bin/false mysql
$> mkdir -p /data/tmp/mysql/log
$> touch /data/tmp/mysql/log/mysqld.log
$> chown -R mysql:mysql /data/tmp/mysql
$> chown -R mysql:mysql /data/mysql
$> chmod -R 755 /data/tmp/mysql /data/mysql
$> cd /usr/local
$> tar xvf mysql-8.0.31-el7-x86_64.tar.gz
$> ln -s mysql-8.0.31-el7-x86_64.tar.gz mysql
$> cd mysql
$> bin/mysqld --initialize --user=mysql
$> bin/mysql_ssl_rsa_setup
$> bin/mysqld_safe --user=mysql &
# Next command is optional
$> cp support-files/mysql.server /etc/init.d/mysql.server
/etc/init.d/mysql.server start
快捷链接
export PATH=${PATH}:/data/mysql/bin
修改密码
$> mysql
mysql> FLUSH PRIVILEGES;
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';
注释掉/etc/my.cnf文件的skip-grant-tables
修改host域及密码修改
mysql -u root -p (密码登陆)
alter user 'root'@'localhost' identified by '123456';
use mysql;
update user set host='%' where user='root';
flush privileges;
root忘记密码
开启skip-grant-tables
同上面的修改密码一样,不过得知道host域
mysql> ALTER USER 'root'@'%' IDENTIFIED BY 'MyNewPass';