在CentOS 6.5 上yum安装、配置MySQL 5.6

Step1: 检测系统是否自带安装mysql

# yum list installed | grep mysql

Step2: 删除系统自带的mysql及其依赖
命令:

# yum -y remove mysql-libs.x86_64

Step3: 给CentOS添加rpm源,并且选择较新的源
命令:

# wget dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm
# yum localinstall mysql-community-release-el6-5.noarch.rpm
# yum repolist all | grep mysql
# yum-config-manager --disable mysql55-community
# yum-config-manager --enable mysql56-community
# yum-config-manager --disable mysql57-community-dmr
# yum repolist enabled | grep mysql
 
 

安装MySQL

[root@snails ~]# yum -y install mysql-server mysql

修改默认配置

[root@snails ~]# mkdir /data/mysql
[root@snails ~]# vi /etc/my.cnf
[mysqld]
datadir=/data/mysql
socket=/tmp/mysql.sock
symbolic-links=0
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

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

[client] 
socket=/tmp/mysql.sock

启动服务

[root@snails ~]# service mysqld start

检查

[root@snails ~]# netstat -ano |grep 3306
tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      off (0.00/0/0)

修改root密码

[root@snails ~]# mysql -u root
mysql> use mysql;
mysql> update user set password=PASSWORD("GIVE-NEW-ROOT-PASSWORD") where User='root';
mysql> flush privileges;
mysql> quit

贴上我目前运行的配置文件

 [client]  
 port=3306 
 socket=/tmp/mysql.sock 
    
 [mysql] 
 default-character-set=utf8 
    
 [mysqld] 
 user=mysql 
 character-set-server=utf8 
 explicit_defaults_for_timestamp=true 

 #索引和数据缓冲区大小,一般设置物理内存的60%-70%     
 innodb_buffer_pool_size = 1G 
 #缓冲池实例个数,推荐设置4个或8个 
 innodb_buffer_pool_instances = 4 
 #关键参数,0代表大约每秒写入到日志并同步到磁盘,数据库故障会丢失1秒左右事务数据。1为每执行一条SQL后写入到日志并同步到磁盘,I/                                                             O开销大,执行完SQL要等待日志读写,效率低。2代表只把日志写入到系统缓存区,再每秒同步到磁盘,效率很高,如果服务器故障,才会丢失事务数据。对数据安全性要求不是很高的推荐设置2,性能高,修改后效果明显。
 innodb_flush_log_at_trx_commit = 2   
 #默认是共享表空间,共享表空间idbdata文件不断增大,影响一定的I/O性能。推荐开启独立表空间模式,每个表的索引和数据都存在自己独立的表空间中,可以实现单表在不同数据库中移动。 
 innodb_file_per_table = ON 
 #日志缓冲区大小,由于日志最长每秒钟刷新一次,所以一般不用超过16M 
 innodb_log_buffer_size = 8M    

 datadir=/data/mysql 
 socket=/tmp/mysql.sock 

 # 禁止MySQL对外部 连接进行DNS解析
 skip-name-resolve    
 # Disabling symbolic-links is recommended to prevent assorted security risks 
 symbolic-links=0 

 # Recommended in standard MySQL setup 
 sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES  

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

您可以选择一种方式赞助本站