https://blog.csdn.net/m0_55730189/article/details/126716163
MySQL :: Download MySQL Community Server
下载MySQL
https://blog.csdn.net/m0_55730189/article/details/126716163https://blog.csdn.net/m0_55730189/article/details/126716163
把mysql上传至服务器(使用Xshell或者FinalShell)
查看文件
ls
- 1
解压
tar -zxvf mysql-5.7.39-linux-glibc2.12-x86_64.tar.gz
- 1
移动并重命名
mv mysql-5.7.39-linux-glibc2.12-x86_64 /usr/local/mysql
- 1
创建MySQL用户组和用户组并修改权限
groupadd mysql
useradd -r -g mysql mysql
- 1
- 2
创建数据目录并赋予权限
mkdir -p /data/mysql
chown -R mysql:mysql /data/mysql
- 1
- 2
创建mariadb目录
mkdir /var/log/mariadb
- 1
新建mariadb.log文件
touch /var/log/mariadb/mariadb.log
- 1
mysql 用户和用户对目录进行授权
chown -R mysql:mysql /var/log/mariadb
- 1
创建mysql目录
mkdir /var/lib/mysql
- 1
修改mysql目录权限
chmod 777 /var/lib/mysql
- 1
移除、安装依赖
yum remove libnuma.so.1
yum -y install numactl.x86_64
- 1
- 2
配置my.cnf
vim /etc/my.cnf
- 1
内容如下
[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
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
进入MySQL的bin目录
cd /usr/local/mysql/bin/
- 1
初始化
./mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql/ --datadir=/data/mysql/ --user=mysql --initialize
- 1
查看密码,记住随机密码
cat /data/mysql/mysql.err
- 1
把mysql.server复制到/etc/init.d/mysql中
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
- 1
启动MySQL服务
service mysql start
- 1
查看MySQL进程
ps -ef|grep mysql
- 1
进入MySQL
./mysql -u root -p
- 1
输入随机密码
修改密码
SET PASSWORD = PASSWORD('123456');
ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;
FLUSH PRIVILEGES;
- 1
- 2
- 3
修改mysql设置
use mysql
update user set host = '%' where user = 'root';
FLUSH PRIVILEGES;
- 1
- 2
- 3
退出MySQL
exit
- 1
创建MySQL软连接
ln -s /usr/local/mysql/bin/mysql /usr/bin
- 1
以后在任意目录,就可以通过以下命令就可以进入MySQL
mysql -u root -p
- 1
在控制台的防火墙(安全组)新建MySQL的端口规则(默认为3306)