CentOS安装MySQL5.7
原文链接:https://blog.csdn.net/m0_55730189/article/details/126716163
CentOS安装MySQL5.7
MySQL :: Download MySQL Community Server
下载MySQL -->https://dev.mysql.com/downloads/mysql/5.7.html
把mysql上传至服务器(使用Xshell或者FinalShell)
查看文件
ls
解压
tar -zxvf mysql-5.7.39-linux-glibc2.12-x86_64.tar.gz
移动并重命名
mv mysql-5.7.39-linux-glibc2.12-x86_64 /usr/local/mysql
创建MySQL用户组和用户组并修改权限
groupadd mysql
useradd -r -g mysql mysql
创建数据目录并赋予权限
mkdir -p /data/mysql
chown -R mysql:mysql /data/mysql
创建mariadb目录
mkdir /var/log/mariadb
新建mariadb.log文件
touch /var/log/mariadb/mariadb.log
mysql 用户和用户对目录进行授权
chown -R mysql:mysql /var/log/mariadb
创建mysql目录
mkdir /var/lib/mysql
修改mysql目录权限
chmod 777 /var/lib/mysql
移除、安装依赖
yum remove libnuma.so.1 yum -y install numactl.x86_64
配置my.cnf
vim /etc/my.cnf
内容如下
[mysqld] bind-address=0.0.0.0 port=3306 user=mysql basedir=/usr/local/mysql datadir=/data/mysql socket=/var/lib/mysql/mysql.sock log-error=/data/mysql/mysql.err pid-file=/data/mysql/mysql.pid character_set_server=utf8mb4 symbolic-links=0 explicit_defaults_for_timestamp=true [mysqld_safe] log-error=/var/log/mariadb/mariadb.log pid-file=/var/run/mariadb/mariadb.pid [client] port=3306 socket=/var/lib/mysql/mysql.sock
进入MySQL的bin目录
cd /usr/local/mysql/bin/
初始化
./mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql/ --datadir=/data/mysql/ --user=mysql --initialize
查看密码,记住随机密码
cat /data/mysql/mysql.err
把mysql.server复制到/etc/init.d/mysql中
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
启动MySQL服务
service mysql start
查看MySQL进程
ps -ef|grep mysql
进入MySQL
./mysql -u root -p
输入随机密码
修改密码
SET PASSWORD = PASSWORD('123456'); ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER; FLUSH PRIVILEGES;
修改mysql设置
use mysql update user set host = '%' where user = 'root'; FLUSH PRIVILEGES;
退出MySQL
exit
创建MySQL软连接
ln -s /usr/local/mysql/bin/mysql /usr/bin
以后在任意目录,就可以通过以下命令就可以进入MySQL
mysql -u root -p
在控制台的防火墙(安全组)新建MySQL的端口规则(默认为3306)
文章知识点与官方知识档案匹配,可进一步学习相关知识
原文链接:https://blog.csdn.net/m0_55730189/article/details/126716163