复制粘贴就完事的Linux 安装MySQL5.6步骤

1.下载MySQL的tar.gz包,如我下载的mysql-5.6.46-linux-glibc2.12-x86_64.tar.gz
2.上传到opt目录下,解压文件

tar -zxvf mysql-5.6.46-linux-glibc2.12-x86_64.tar.gz

3.移动到/usr/local/目录下,并改名

mv mysql-5.6.46-linux-glibc2.12-x86_64 /usr/local/mysql

4.创建用户和用户组

groupadd mysql
useradd -r -g mysql mysql

5.将安装目录所有者及所属组改为mysql

chown -R mysql.mysql /usr/local/mysql

6.安装初始化

cd /usr/local/mysql/scripts/

执行

./mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/

7.编辑配置文件 /etc/my.cnf

[mysqld]
datadir=/usr/local/mysql/data
basedir=/usr/local/mysql
socket=/tmp/mysql.sock
user=mysql
port=3306
character-set-server=utf8
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# skip-grant-tables
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

8.将mysql加入到服务

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

9.开机启动

chkconfig mysql on

10.启动mysql

service mysql start

11.设置mysql密码(默认为host为localhost,即只能当前本地服务器登陆,此时root用户都没有密码),下面的命令将root的在各个host的密码都改为一样的密码

/usr/local/mysql/bin/mysql -uroot -p
use mysql;
update user set password = PASSWORD('密码')where user='root';
flush privileges;
exit;

12.设置可以远程连接,将host改为%代表可以外网访问,这里可以新建一个可以支持外网访问的用户

create user 'test'@'%' identified by '密码';
grant all on mysql.* to 'test'@'%'; //授予当前数据库所有外网访问的权限
grant all privileges on *.* to 'test'@'%' //授予所有数据库的所有权限,包括创建数据库等权限
flush privileges;
exit;
点赞