0%

Centos7安装MySQL5.6

Centos7系统,以rpm方式安装MySQL5.6


参考教程

卸载MySQL

rpm -qa | grep MySQL
rpm -e —nodeps mysql MySQL-server-5
rpm -e —allmatches MySQL-client-5.6.33-1.el7.x86_64
rpm -e —allmatches MySQL-devel-5.6.33-1.el7.x86_64
rpm -e —allmatches MySQL-server-5.6.33-1.el7.x86_64
chkconfig —del mysql
rm -rf /user/local/mysql
rm -rf /etc/my.cnf
rm -rf /var/lib/mysql

准备mysql安装文件

下载 mysql包:wget http://cdn.mysql.com//Downloads/MySQL-5.6/mysql-5.6.33-winx64.zip
解压缩:tar -xvf mysql-5.6.33-winx64.zip

安装MySQL

1
2
3
4
su mysql
rpm -ivh MySQL-server-5.6.33-1.el7.x86_64.rpm
rpm -ivh MySQL-devel-5.6.33-1.el7.x86_64.rpm
rpm -ivh MySQL-client-5.6.33-1.el7.x86_64.rpm

修改配置文件位置

cp /usr/share/mysql/my-default.cnf /etc/my.cnf

初始化MySQL及设置密码

安装server会自动执行数据库初始化(perl):/usr/bin/mysql_install_db
启动服务:service mysql start
查看默认密码:cat /root/.mysql_secret
修改root密码:

1
2
3
mysql -uroot -pFiXBgAhVDgythr6B
SET PASSWORD = PASSWORD('root');
exit

允许远程登陆

1
2
3
4
5
mysql -uroot -proot
use mysql;
update user set host='%' where user='root' and host='localhost';
flush privileges;
exit

设置开机自启动

1
2
chkconfig mysql on
chkconfig --list | grep mysql

配置/etc/my.cnf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#  whereis my.ini
[server]
bind-address = 0.0.0.0
character-set-server = utf8
collation-server = utf8_unicode_ci
init_connect = 'SET NAMES utf8'
max_connections = 5000
max_allowed_packet = 20M
max_connect_errors= 1000
lower_case_table_names=2

[mysqld]
data=/usr/local/mysql/data
socket=/var/lib/mysql/mysql.sock

innodb_file_per_table = 1
innodb_flush_method=O_DIRECT
innodb_log_file_size=1G
innodb_buffer_pool_size=4G

[mysqld_safe]
log-error=/var/log/mysqld.log
long_query_time =1
log-slow-queries=slowqueris.log
log-queries-not-using-indexes = nouseindex.log
log=mylog.log

mysql数据目录设置权限

1
2
3
su root
chown -R root:root /usr/local/mysql/data
chown -R root:root /var/lib/mysql