Loading
0

CentOS 7 安装mysql

卸载Mariadb:

rpm -qa | grep mariadb;
rpm -e --nodeps mariadb-libs-5.5.68-1.el7.x86_64;

关闭selinux:

setenforce 0;
sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config;
grep 'SELINUX=disabled' /etc/selinux/config;

下载安装包:

wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.38-1.el7.x86_64.rpm-bundle.tar

查看初始密码:

grep 'temporary password' /var/log/mysqld.log 

修改默认密码:

alter user user() identified by 'JoyCode@2022';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'JoyCode@2022'; #8以前
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;#8以后
flush privileges;

修改mysql数据目录:

vi /etc/my.cnf

下面是修改过的示例:

[mysqld]
datadir=/data/mysql
socket=/data/mysql/mysql.sock
lower_case_table_names=1
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
[client]
socket=/data/mysql/mysql.sock

配置新目录权限:

chown -R mysql:mysql /data/mysql;
chmod -R 755 /data

拷贝原数据目录文件到新数据目录:

cp -r /var/lib/mysql /data/mysql

创建sock软链接:

ln -s /data/mysql/mysql.sock /var/lib/mysql/mysql.sock;

防火墙开端口:

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

参考:

最后编辑于:2022/7/5作者: joycode

评论已关闭