酒诡 发表于 2023-10-21 21:52:25

Linux运维Centos7.6篇《MySQL安装》

1.创建用户组
groupadd mysql

2.创建用户,并将用户加入mysql组,且禁止远程shell登录
useradd -r -g mysql -s /bin/false mysql

3.将mysql二进制文件解压至/usr/local
tar -axvf mysql.tar.gz -C /usr/local

4.重命名文件夹
cd cd /usr/local/
mv mysql-5.7.40 mysql

5.初始化数据库
cd /usr/local/mysql/
mkdir mysql-files
chown mysql:mysql mysql-files
chmod 750 mysql-files
bin/mysqld --initialize --user=mysql
bin/mysql_ssl_rsa_setup

bin/mysqld_safe --user=mysql

启动mysql后,注意密码这个字符串打印
A temporary password is generated for root@localhost: a88EGrzvjS?j

此时临时生成了密码为 a88EGrzvjS?j

5.修改mysql密码
cd /usr/local/mysql/bin/
./mysql -uroot -p

ALTER USER USER() IDENTIFIED BY '此处为新密码';
允许远程mysql
update mysql.user set Host='%' where User='root';

6.防火墙放行

firewall-cmd --zone=public --add-port=3306/tcp --permanent
firewall-cmd --reload

7.配置系统服务
cp support-files/mysql.server /etc/init.d/mysql.server

编辑文件/etc/init.d/mysql.server
修改basedir
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data

重载服务
systemctl daemon-reload

停止服务 service mysql stop
启动服务service mysql start

设置开机启动
systemctl enable mysql.server
页: [1]
查看完整版本: Linux运维Centos7.6篇《MySQL安装》