Centos6.6安装mysql记录
Posted 灬魑魅魍魉灬
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Centos6.6安装mysql记录相关的知识,希望对你有一定的参考价值。
一、环境介绍:
系统:Cerntos6.6
mysql版本:mysql-5.6.34
二、安装操作:
1、卸载旧版本:
rpm -qa |grep mysql mysql-server-5.1.73-8.el6_8.x86_64 mysql-libs-5.1.73-8.el6_8.x86_64 mysql-5.1.73-8.el6_8.x86_64 删除/etc/my.cnf: rm -f /etc/my.cnf rpm -e mysql-libs-5.1.73-8.el6_8.x86_64 mysql-5.1.73-8.el6_8.x86_64 --nodeps #强制删除
注:在CentOS 6.4版操作系统最小安装完成后,默认会在/etc目录下存在一个my.cnf,需要将此文件更名为其他的名字,如:/etc/my.cnf.bak,否则,该文件会干扰源码安装的MySQL的正确配置,造成无法启动。
在使用"yum update"更新系统后,需要检查下/etc目录下是否会多出一个my.cnf,如果多出,将它重命名成别的。否则,MySQL将使用这个配置文件启动,可能造成无法正常启动等问题。
2、安装依赖包:
yum -y install make gcc-c++ cmake bison-devel ncurses-devel groupadd mysql #有用户的话删除就行 userdel mysql useradd -g mysql mysql -M -s /sbin/nologin
3、下载MySQL,源码编译安装:
cd /usr/local/src 下载安装包: 百度云盘链接:http://pan.baidu.com/s/1hs8awRU 密码:ly4d tar -zxvf mysql-5.6.34.tar.gz cd mysql-5.6.34/ cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql/data -DSYSCONFDIR=/etc -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock -DMYSQL_TCP_PORT=3306 -DENABLED_LOCAL_INFILE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci make && make install
4、配置MySQL:
修改/usr/local/mysql权限 mkdir -p /data/mysql/data chown -R mysql:mysql /usr/local/mysql chown -R mysql:mysql /data/mysql/data 执行初始化配置脚本,创建系统自带的数据库和表 cd /usr/local/mysql ./scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/data/mysql/data --user=mysql #如果后续不小心删除了这个数据目录或这个目录下的文件被误操作删除了,可以利用这个命令重新初始化。 cp support-files/mysql.server /etc/init.d/mysql chkconfig mysql on service mysql start //启动前,要先配置my.cnf文件(如下), 并确保/data/mysql/data和/usr/local/mysql的mysql权限
[client] port = 3306 socket = /usr/local/mysql/var/mysql.sock [mysqld] port = 3306 socket = /usr/local/mysql/var/mysql.sock basedir = /usr/local/mysql/ datadir = /data/mysql/data pid-file = /data/mysql/data/mysql.pid user = mysql bind-address = 0.0.0.0 server-id = 1 sync_binlog=1 log_bin = mysql-bin skip-name-resolve back_log = 600 max_connections = 3000 max_connect_errors = 3000 table_open_cache = 512 max_allowed_packet = 16M binlog_cache_size = 16M max_heap_table_size = 16M tmp_table_size = 256M read_buffer_size = 1024M read_rnd_buffer_size = 1024M sort_buffer_size = 1024M join_buffer_size = 1024M key_buffer_size = 8192M thread_cache_size = 8 query_cache_size = 512M query_cache_limit = 1024M ft_min_word_len = 4 binlog_format = mixed expire_logs_days = 30 log_error = /data/mysql/data/mysql-error.log slow_query_log = 1 long_query_time = 1 slow_query_log_file = /data/mysql/data/mysql-slow.log performance_schema = 0 explicit_defaults_for_timestamp skip-external-locking default_storage_engine = InnoDB innodb_file_per_table = 1 innodb_open_files = 500 innodb_buffer_pool_size = 1024M innodb_write_io_threads = 1000 innodb_read_io_threads = 1000 innodb_thread_concurrency = 8 innodb_purge_threads = 1 innodb_flush_log_at_trx_commit = 2 innodb_log_buffer_size = 4M innodb_log_file_size = 32M innodb_log_files_in_group = 3 innodb_max_dirty_pages_pct = 90 innodb_lock_wait_timeout = 120 bulk_insert_buffer_size = 8M myisam_sort_buffer_size = 8M myisam_max_sort_file_size = 10G myisam_repair_threads = 1 interactive_timeout = 28800 wait_timeout = 28800 [mysqldump] quick max_allowed_packet = 16M [myisamchk] key_buffer_size = 8M sort_buffer_size = 8M read_buffer = 4M write_buffer = 4M sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES port = 3306
启动报错的话:
[[email protected] mysql]# ERROR 2002 (HY000): Can‘t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock‘ (111) 登录报以上错误的话,删除/var/lib/mysql/mysql.sock这个文件: rm -f /var/lib/mysql/mysql.sock ln -s /usr/local/mysql/var/mysql.sock /var/lib/mysql/mysql.sock
以上是关于Centos6.6安装mysql记录的主要内容,如果未能解决你的问题,请参考以下文章