Bootstrap

CentOS7 mysql-8.0.17 安装

MySQL 安装

卸载 mariadb

# 查看 mariadb 的安装包
rpm -qa | grep mariadb
# 卸载 mariadb 的安装包
rpm -e  mariadb-libs-5.5.60-1.el7_5.x86_64 --nodeps
# 再次查看
rpm -qa | grep mariadb

下载MySQL包

# 从官网下载
wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.17-linux-glibc2.12-x86_64.tar.xz
# 从华为云下载
wget https://mirrors.huaweicloud.com/mysql/Downloads/MySQL-8.0/mysql-8.0.17-linux-glibc2.12-x86_64.tar.xz
# 解压
tar xvJf mysql-8.0.17-linux-glibc2.12-x86_64.tar.xz
# 创建目录
mkdir /mysql
# 移动文件
mv mysql-8.0.17-linux-glibc2.12-x86_64 /mysql/
cd /mysql/mysql-8.0.17-linux-glibc2.12-x86_64
mv * ../
cd ..
rm -rf mysql-8.0.17-linux-glibc2.12-x86_64

配置文件

vim /etc/my.cnf

文件内容

[client]
port=3306
socket=/var/run/mysql/mysql.sock
default-character-set=utf8mb4
[mysqld]
user=mysql
server-id=1
port=3306
mysqlx_port=33060
mysqlx_socket=/var/run/mysql/mysqlx.sock
basedir=/mysql
datadir=/mysql/data
socket=/var/run/mysql/mysql.sock
pid-file=/var/run/mysql/mysqld.pid
log-error=/mysql/logs/error.log
slow-query-log=1
slow-query-log-file=/mysql/logs/slow.log
long_query_time=0.2
log-bin=/mysql/logs/bin.log
relay-log=/mysql/logs/relay.log
binlog_format=ROW
relay_log_recovery=1
character-set-client-handshake=FALSE
character-set-server=utf8mb4
collation-server=utf8mb4_unicode_ci
init_connect ='SET NAMES utf8mb4'
innodb_buffer_pool_size=1G
join_buffer_size=128M
sort_buffer_size=2M
read_rnd_buffer_size=2M
log_timestamps = SYSTEM
lower_case_table_names = 1
default-authentication-plugin=mysql_native_password
#skip-grant-tables

配置

cd /mysql
# 创建data和logs目录
mkdir data
mkdir logs
# 创建mysql 运行文件
mkdir -p /var/run/mysql/
# 修改文件夹用户归属
chown -R mysql:mysql /var/run/mysql/
chown -R mysql:mysql /mysql
chmod 777 /var/run/mysql
chmod 775 /mysql -R
# link
ln -s /mysql/bin/mysql /usr/local/bin
ln -s /mysql/bin/mysqld /usr/local/bin
# 初始化
mysqld --initialize --console
# 获取密码
cat logs/error.log |grep password
# 添加mysql到服务中
cp support-files/mysql.server /etc/init.d/mysql
# 设置安装目录和data目录 参数值与/etc/my.cnf中一样
vim /etc/init.d/mysql
# 修改如下内容
basedir=/mysql
datadir=/mysql/data
mkdir /var/run/mysql
chmod -R 777 /var/run/mysql
chown -R mysql:mysql /var/run/mysql/
# 加载
systemctl daemon-reload
# link
ln -s /run/mysql/mysql.sock /tmp/mysql.sock
# 启动
systemctl start mysql
# 查看运行状态
systemctl status mysql
# 开机启动
systemctl enable mysql

MySQL配置

mysql -p -S /var/run/mysql/mysql.sock
# 修改root账户密码
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';
exit;
# 退出使用新密码登录
mysql -uroot -p
# 创建远程操作账户,进行远程访问的授权
create user 'root'@'%' identified with mysql_native_password by '123456';
grant all privileges on *.* to 'root'@'%' with grant option;
flush privileges;
;