关于mysql:centossuse安装离线mysql

52次阅读

共计 2011 个字符,预计需要花费 6 分钟才能阅读完成。

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

以上装置结束

正文完
 0