mysql-5.6.22的安装步骤

一、环境与下载地址:

1、系统下载地址:

http://mirrors.sohu.com/centos/6.6/isos/x86_64/CentOS-6.6-x86_64-bin-DVD1.iso

2、mysql下载地址:

 
推荐使用官方
 
 
二、安装mysql的步骤:
1、卸载原版本的mysql:
yum -y remove mysql-libs-5.1*
或者
rpm -e  原始mysql
 
 
2、创建一个MySQL用户组:
groupadd mysql
 
3、一个属于MySQL的用组的mysql用户
useradd -g mysql -s /sbin/nologin -d /opt/mysql mysql
 
 
4、查看用户和组状态:
id mysql
uid=500(mysql) gid=500(mysql) groups=500(mysql)
 
 
 
5、配置myql的安装目录:
mkdir -p /opt/mysql/mysql-5.6.22
mkdir -p /data/mysql/mysql_3306/{data,tmp,logs}
ln -s /opt/mysql/mysql-5.6.22  /usr/local/mysql
ll /usr/local/
 
 
6、查看结果:
ll /usr/local/
lrwxrwxrwx  1 root root   23 Dec 17 15:24 mysql -> /opt/mysql/mysql-5.6.22
 
 
 
7、解压mysql的安装包:
tar -xzvf /data/soft/mysql-5.6.22-linux-glibc2.5-x86_64.tar.gz -C /opt/mysql/mysql-5.6.22/
 
 
 
8、剪贴文件到安装目录:
cd /opt/mysql/mysql-5.6.22
mv mysql-5.6.22-linux-glibc2.5-x86_64/* .
 
 
 
9、查看依赖的lib库是否安全
ldd /usr/local/mysql/bin/mysqld
 
 
 
10、更改权限:
chown -R mysql:mysql /usr/local/mysql/
chown -R mysql:mysql /data/mysql/
chown -R mysql:mysql /opt/mysql/
 
 
 
11、设置root的环境变量:
vi .bash_profile
export PATH=/usr/local/mysql/bin:/opt/mysql/mysql-5.6.22/bin:$HOME/bin:$PATH
source .bash_profile
 
 
 
 
12、编辑my.cnf
#my.cnf
[client]
port            = 3306
socket          = /tmp/mysql.sock
 
[mysql]
prompt=[master]>
#pager="less -i -n -S"
tee=/data/mysql/mysql_3306/data/query.log
no-auto-rehash
 
[mysqld_multi]
mysqld = /usr/local/mysql/bin/mysqld_safe
mysqladmin = /usr/local/mysql/bin/mysqladmin
log = /opt/mysql/mysqld_multi.log
 
[mysqld]
#misc
explicit_defaults_for_timestamp = ture
user = mysql
basedir = /usr/local/mysql
datadir = /data/mysql/mysql_3306/data
port = 3306
socket = /tmp/mysql.sock
event_scheduler = 0
 
#timeout
interactive_timeout = 300
wait_timeout = 300
 
#character set
character-set-server = utf8
 
open_files_limit = 65535
max_connections = 100
max_connect_errors = 100000
 
skip-name-resolve = 1
#logs
log-output=file
slow_query_log = 1
slow_query_log_file = slow.log
log-error =  /data/mysql/mysql_3306/data/error.log
log_warnings = 2
pid-file = mysql.pid
long_query_time = 1
#log-slow-admin-statements = 1
#log-queries-not-using-indexes = 1
log-slow-slave-statements = 1
 
#binlog
binlog_format = mixed
server-id = 2003306
log-bin = /data/mysql/mysql_3306/logs/mybinlog
binlog_cache_size = 4M
max_binlog_size = 1G
max_binlog_cache_size = 2G
sync_binlog = 0
expire_logs_days = 10
 
#relay log
skip_slave_start = 1
max_relay_log_size = 1G
relay_log_purge = 1
relay_log_recovery = 1
log_slave_updates
#slave-skip-errors=1032,1053,1062
 
#buffers & cache
table_open_cache = 2048
table_definition_cache = 2048
table_open_cache = 2048
max_heap_table_size = 96M
sort_buffer_size = 2M
join_buffer_size = 2M
thread_cache_size = 256
query_cache_size = 0
query_cache_type = 0
query_cache_limit = 256K
query_cache_min_res_unit = 512
thread_stack = 192K
tmp_table_size = 96M
key_buffer_size = 8M
read_buffer_size = 2M
read_rnd_buffer_size = 16M
bulk_insert_buffer_size = 32M
 
#myisam
myisam_sort_buffer_size = 128M
myisam_max_sort_file_size = 10G
myisam_repair_threads = 1
 
#innodb
innodb_buffer_pool_size = 100M
innodb_buffer_pool_instances = 1
innodb_data_file_path = ibdata1:1G:autoextend
innodb_flush_log_at_trx_commit = 1
innodb_log_buffer_size = 64M
innodb_log_file_size = 256M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 50
innodb_file_per_table = 1
innodb_rollback_on_timeout
innodb_status_file = 1
innodb_io_capacity = 2000
transaction_isolation REPEATABLE-READ
innodb_flush_method = O_DIRECT
 
#端口号为3306的实例特殊配置
[mysqld3306]
port =3306
#指定本实例相应版本的basedir和datadir
basedir= /usr/local/mysql
datadir = /data/mysql/mysql_3306/data
socket          = /tmp/mysql_3306.sock
#重新配置这几个选项,不与全局配置一样,会直接覆盖上面的全局设置
innodb_buffer_pool_size = 100m
transaction_isolation = REPEATABLE-READ
 
[mysqld3308]
port=3308
basedir= /usr/local/mysql
datadir = /data/mysql/mysql_3308/data
socket          = /tmp/mysql_3308.sock
#重新配置这几个选项,不与全局配置一样,会直接覆盖上面的全局设置
innodb_buffer_pool_size = 100m
innodb_flush_log_at_trx_commit = 2
sync_binlog = 0
 
 
 
13、复制my.cnf到/etc/目录下:
cp my.cnf  /etc/my.cnf
 
 
 
14、初始化数据库:
cd /usr/local/mysql/
初始化数据库一定要在basedir 下进行
./scripts/mysql_install_db --user=mysql --defaults-file=/etc/my.cnf
 
 
15、将启动信息加入到启动像
cd  /usr/local/mysql
cp support-files/mysql.server /etc/init.d/mysql
 
 
 
16、启动mysql服务:
/etc/init.d/mysql start
 
 
17、查看mysql是否启动成功:
 
a、查看mysql的进程:
ps axu|grep mysqld
 
 
b、查看mysql的监听:
netstat -nalp|grep "3306"
 
 
18、添加启动项:
chkconfig --add mysql
chkconfig --level 35 mysql on
chkconfig --list |grep mysql
mysql           0:off 1:off 2:on 3:on 4:on 5:on 6:off
 
 
 
19、查看mysql用户的表信息:
select user,host,password from mysql.user;
+------+-----------+----------+
| user | host      | password |
+------+-----------+----------+
| root | localhost |          |
| root | master1   |          |
| root | 127.0.0.1 |          |
| root | ::1       |          |
|      | localhost |          |
|      | master1   |          |
+------+-----------+----------+
6 rows in set (0.00 sec)
 
 
20、删除初始化用户:
delete from mysql.user where user!=‘root‘ or host!=‘localhost‘;
 
 
21、刷新数据库:
flush privileges;
 
22、检查权限:
select user,host,password from mysql.user;
 
 
=========================================================
安装时出现的问题大多数的排错思路如下:
1、初始化mysql的时候,需要开启另一个连接,tail -f error.log,根据报错进行查看。
2、查看my.cnf文件里的目录是否都存在。
3、查看my.cnf文件里的目录权限是否都是mysql.mysql。
4、如果是虚拟机查看内存和磁盘是否足够。
 
 
 
 
 
 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。