安装MySQL5.7

 

1.下载安装包

wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz

更多的下载地址

 

2.解压

sudo tar -zxvf mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz

 

3.移到指定位置

sudo mv mysql-5.7.38-linux-glibc2.12-x86_64 /usr/local/mysql5.7

 

3.添加用户

sudo groupadd mysql
sudo useradd -r -g mysql mysql

 

4.配置目录

sudo mkdir -p /data/db/mysql
sudo chown mysql:mysql -R /data/db/mysql/

 

5.配置my.cnf文件

sudo vi /etc/my.cnf

参考内容

 

 

6.初始化数据库

sudo /usr/local/mysql5.7/bin/mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql5.7/ --datadir=/data/db/mysql --user=mysql --initialize

 

如果发生如下报错

 

 执行:

yum install libaio

或

apt-get install libaio-dev

 

 

 

sudo cp /usr/local/mysql5.7/support-files/mysql.server /etc/init.d/mysql

sudo mkdir /var/log/mariadb
//创建一个空文件
sudo vi /var/log/mariadb/mariadb.log
sudo chown mysql:mysql -R /var/log/mariadb
sudo service mysql start

 

如果碰到如下错误

 

 解决:

mkdir   /var/lib/mysql
chmod 777  /var/lib/mysql

 

 

查看默认密码

cat /data/logs/mysql.err 

 

 

 

修改默认密码

mysql -u root -p

SET PASSWORD = PASSWORD('12345678');
ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;
FLUSH PRIVILEGES;

 

 

 

开启远程连接

use mysql;
update user set host = '%' where user = 'root';
FLUSH PRIVILEGES;

 

posted @ 2022-06-09 14:40  幻河  阅读(64)  评论(0编辑  收藏  举报