1、下载
wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.33-linux-glibc2.5-x86_64.tar.gz
2、解压
tar -zxvf mysql-5.6.33-linux-glibc2.5-x86_64.tar.gz
3、移动安装目录
mv mysql-5.6.33-linux-glibc2.5-x86_64 /usr/local/mysql
4、添加用户和组
groupadd mysql
useradd -g mysql mysql
5、安装mysql
①进入mysql目录:cd /usr/local/mysql
②把目录权限分配给mysql组下的mysql用户:chown -R mysql:mysql ./
③安装mysql:./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
安装mysql语句报错执行,出现/usr/bin/perl: bad interpreter: No such file or directory
执行:yum install -y perl perl-devel
如果还出现please install the following Perl modules before executing ./scripts/mysql_install_db:Data::Dumper
执行:yum install -y perl-Module-Install
6、编辑配置文件
①进入目录:cd /usr/local/mysql/support-files
②复制配置文件:cp my-default.cnf /etc/my.cnf
③添加系统服务、开机自启动:
先复制文件:cp mysql.server /etc/init.d/mysql
开机启动:chkconfig mysql on
④配置my.cnf:编辑文件:vim /etc/my.cnf,添加以下内容
[mysql]
default-character-set=utf8
[mysqld]
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
port=3306
socket=/tmp/mysql.sock
symbolic-links=0
character-set-server=utf8
default-storage-engine=INNODB
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
7、添加环境变量
①编辑文件:vim /etc/profile
②添加以下两行环境变量:
export PATH=/usr/local/mysql/bin:$PATH
③设置环境变量生效:source /etc/profile
④软连接:ln -fs /usr/local/mysql/bin/mysql /usr/bin
8、启动mysql
service mysql start
9、修改密码
①mysql刚安装完毕没有密码进入mysql命令行:mysql -uroot -p
②查询mysql用户:select User, Host, Password FROM mysql.user;
③修改root密码:update mysql.user set password=password('password') where User="root";
④刷新权限:flush privileges;
10、添加远程访问权限
①登录mysql:mysql -uroot -ppassword
②使用mysql:use mysql;
③为root添加远程权限,%号表示允许任何ip访问数据库:grant all privileges on *.* to root@"%" identified by "password";
④刷新权限:flush privileges;
⑤重启mysql:service mysql restart
11、关闭防火墙
systemctl stop firewalld.service
systemctl disable firewalld.service
或者:
systemctl stop firewalld
systemctl disable firewalld
以上mysql5.6安装完成。