linux安装mysql5.7.20,亲测

shell>tar -zxvf mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
shell>mv mysql-5.7.20-linux-glibc2.12-x86_64/ mysql
shell> groupadd mysql
shell> useradd -r -g mysql -s /bin/false mysql
shell> cd /usr/local
shell> cd mysql
shell> mkdir mysql-files
shell> chmod 750 mysql-files
shell> chown -R mysql .
shell> chgrp -R mysql .
shell> bin/mysqld --initialize --user=mysql //这个命令执行完之后会出现默认密码如下图:

linux安装mysql5.7.20,亲测_第1张图片

shell> bin/mysql_ssl_rsa_setup              # MySQL 5.7.6 and up
shell> chown -R root .
shell>bin/mysqld_safe --user=mysql &  //(坑)执行这步的是为了生成pid,当你看到以.pid ended结尾,就可以ctrl+c,而且这一步mysql已经启动了,你需要执行ps -ef|grep mysqld,然后将mysql进程kill掉,然后在进行一下命令
shell>cd ..
shell> sudo support-files/mysql.server start //开启mysql,他会报错,需要修改/etc/my.cnf下的socket=/tmp/mysql.sock,修改完成后再次启动mysql
shell> cp support-files/mysql.server /etc/init.d/mysql.server//设置开机启动

修改默认密码:

mysql> SET PASSWORD = PASSWORD('123456'); 

任意主机能连接:

mysql>GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'%' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;
mysql>flush privileges;

下边是my.cnf配置文件:

[mysqld]
datadir=/var/lib/mysql
socket=/tmp/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

你可能感兴趣的:(mysql)