1. 检查操作系统是否有自带的mysql相关包并卸载

rpm -qa |grep mariadb||mysql||percona
rpm -e mariadb-libs-5.5.68-1.el7.x86_64

如果报错依赖其他的什么包,也使用 rpm -e 卸载掉

2. 获取mysql的软件包

cd /opt; wget https://repo.huaweicloud.com/mysql/Downloads/MySQL-5.7/mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz

3. 安装和初始化mysql

# 解压并修改目录名称
tar -zxvf mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz
mv mysql-5.7.31-linux-glibc2.12-x86_64 mysql

# 创建用户及所属组
groupadd mysql ; useradd -d /home/mysql -s /bin/bash -g mysql -m mysql
chown -R mysql:mysql /opt/mysql

# 创建数据盘目录(有条件可以给/data01目录单独挂数据盘,没条件可以不挂)
mkdir -p /data01/mysql-data/tmp
mkdir -p /data01/mysql-data/log
mkdir -p /data01/mysql-data/workdbs
chown -R mysql:mysql /data01/mysql-data/

# 创建my.cnf文件,并输入以下内容:

cd /opt/mysql;vim my.cnf

### 以下为文件内容


[mysqld]
basedir = /opt/mysql/
bind-address = 192.168.74.129
datadir =  /data01/mysql-data/workdbs
tmpdir =  /data01/mysql-data/tmp
port = 3306
socket = /opt/mysql/lib/mysql.sock
lower_case_table_names = 1
character-set-server = utf8 
max_allowed_packet = 150M
sql_mode = STRICT_ALL_TABLES,STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION
log-error = /data01/mysql-data/log/mysql-3306.log
max_connections = 1000
event_scheduler = ON
[mysql]
default-character-set = utf8 
socket = /opt/mysql/lib/mysql.sock

# 修改文件权限
chown mysql:mysql /opt/mysql/my.cnf
cp -fr /opt/mysql/my.cnf /etc/my.cnf


# 修改系统配置文件,行尾声明path

# vim /etc/profile

export PATH=$PATH:/opt/mysql/bin
export PATH=$PATH:/etc/init.d

# 加载环境变量
source /etc/profile

# 拷贝support文件

cd /opt/mysql; cp -a ./support-files/mysql.server /etc/init.d/mysql.server

# 初始化mysql

cd /opt/mysql; ./bin/mysqld --initialize --user=mysql --basedir=/opt/mysql --datadir=/data01/mysql-data/workdbs

# 获取mysql初始密码

类似于下面这样
cat /data01/mysql-data/log/mysql-3306.log
### 2021-03-04T02:13:45.980203Z 1 [Note] A temporary password is generated for root@localhost: gRaEoQl)z3eQ

# 创建软连接

ln -s /opt/mysql /usr/local/mysql
ln -s /opt/mysql/lib/mysql.sock /tmp/mysql.sock


# 启动mysql服务

systemctl enable mysql.server
cd /opt/mysql/support-files ; mysql.server start; 

# 修改root用户名和密码

mysql -uroot -p
set password=password("123");
grant all privileges on *.*  to 'root'@'%' identified by '123' with grant option;
flush privileges;
use mysql;
# 查看授权正确
select host,user from user;

exit

以上安装完毕


江帆孤影
1 声望0 粉丝

菜鸡测试狗