美文网首页
Linux安装MySQL5.7

Linux安装MySQL5.7

作者: 皮蛋馅儿 | 来源:发表于2019-12-03 11:58 被阅读0次

一、检查是否已经安装过MySQL

rpm -qa | grep mysql

二、检查用户名和用户组是否已经创建,没有就创建

cat /etc/group | grep mysql
cat /etc/passwd |grep mysql
groupadd mysql
useradd -r -g mysql mysql

三、/usr/local/目录下,下载安装包

cd /usr/local

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

四、解压安装包,并且删除压缩包

tar xzvf mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
image.png

删除压缩包(可不删,或者避免意外安装完成后再删除)

rm -rf mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz

重命名为mysql

mv mysql-5.7.24-linux-glibc2.12-x86_64 mysql

五、创建data文件夹

mkdir /usr/local/mysql/data

六、修改mysql目录下所有目录及文件夹所属的用户组和用户、权限

chown -R mysql:mysql /usr/local/mysql
chmod -R 755 /usr/local/mysql

七、编译安装MySQL,切记保存下最后的mysql管理员临时密码

cd /usr/local/mysql/bin
./mysqld --initialize --user=mysql --datadir=/usr/local/mysql/data --basedir=/usr/local/mysql
image.png

八、修改my.cnf

vi /etc/my.cnf

[mysqld]
datadir=/usr/local/mysql/data
port = 3306
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
symbolic-links=0
max_connections=400
innodb_file_per_table=1
#表名大小写不明感,敏感为
lower_case_table_names=1
socket=/usr/local/mysql/data/mysql.sock
image.png

九、启动mysql

/usr/local/mysql/support-files/mysql.server start

可能出现的报错:

Starting MySQL.2019-12-03T03:15:10.750726Z mysqld_safe error: log-error set to '/var/log/mariadb/mariadb.log', however file don't exists. Create writable for user 'mysql'.
 ERROR! The server quit without updating PID file (/usr/local/mysql/data/localhost.localdomain.pid).

解决:

mkdir /var/log/mariadb
touch /var/log/mariadb/mariadb.log
chown -R mysql:mysql /var/log/mariadb/

启动成功如下:


image.png

十、添加软链接,重启服务

ln -s /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql
service mysql restart

十一、登录mysql,修改密码

mysql -u root -p

回车,输入上面要求保存的临时密码

set password for root@localhost = password('123456'); (123456是新的密码,可自行设置)

可能出现的报错:

Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

因为上面我们配置了socket=/usr/local/mysql/data/mysql.sock
解决:

ln -s /usr/local/mysql/data/mysql.sock /tmp/mysql.sock

十二、开放远程连接

use mysql;
update user set user.Host='%' where user.User='root';
flush privileges;

十三、设置开机自启动

cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld

chmod +x /etc/init.d/mysqld

chkconfig --add mysqld

chkconfig --list
image.png

加我微信公众号【皮蛋馅儿】,一起学习哦~

相关文章

网友评论

      本文标题:Linux安装MySQL5.7

      本文链接:https://www.haomeiwen.com/subject/jaoxgctx.html