MYSQL数据库安装文档
本文档是MYSQL-5.6.25在CENTOS 6.5 64位版本上安装的文档,经过测试并没有发现问题。
安装以前先查看服务器里是否有老版本的MYSQL已经被安装了
rpm -qa |grep mysql
如果有就删除掉旧版本的MYSQL即可
rpm -e (上面那条命令得到的信息) --nodeps
一.解压 软连接 改目录名称
解压
tar xzvf mysql-5.6.25-linux-glibc2.5-x86_64.tar.gz
改目录名称
mv mysql-5.6.25-linux-glibc2.5-x86_64 mysql
二.创建目录
mkdir -p /data/mysql_data
mkdir -p /data/mysql_log
mkdir -p /data/log-bin
groupadd mysql
useradd -g mysql mysql
chown -R mysql.mysql /data/mysql_data /data/mysql_log /data/log-bin
chown -R mysql.mysql /usr/local/mysql
三.my.cnf(根据自己需求填写,以下只是个大概的例子)
vi /etc/my.cnf
[mysqld]
GENERAL
user = mysql
default-storage-engine = InnoDB
socket = /data/mysql_data/mysql.sock
pid-file = /data/mysql_data/mysql.pid
port = 3306
MyISAM
key_buffer_size = 1000M
myisam_recover = FORCE,BACKUP
SAFETY
max_allowed_packet = 16M
max_connect_errors = 1000000
skip_name_resolve
DATA STORAGE
datadir = /data/mysql_data/
long_query_time = 1
BINARY LOGGING
log-bin = /data/log-bin/mysql-bin-3306
expire-logs-days = 14
sync-binlog = 1
server-id = 1
max_binlog_size = 500M
REPLICATION
relay-log = /data/log-bin/relay-bin-3306
slave-net-timeout = 60
CACHES AND LIMITS
tmp_table_size = 32M
max_heap_table_size = 32M
max_connections = 500
thread_cache_size = 50
open_files_limit = 65535
table_definition_cache = 4096
table_open_cache = 4096
INNODB
innodb_data_file_path = ibdata1:128M;ibdata2:10M:autoextend
innodb_flush_method = O_DIRECT
innodb_log_files_in_group = 2
innodb_lock_wait_timeout = 50
innodb_log_file_size = 256M
innodb_flush_log_at_trx_commit = 1
innodb_file_per_table = 1
innodb_thread_concurrency = 8
innodb_buffer_pool_size = 8G
LOGGING
log-error = /data/mysql_log/mysql-error-3306.log
log-queries-not-using-indexes = 1
slow-query-log = 1
long_query_time = 1
slow-query-log-file = /data/mysql_log/mysql-slow-3306.log
FOR SLAVE
binlog-format = ROW
log-slave-updates = true
gtid-mode = on
enforce-gtid-consistency = true
master-info-repository = TABLE
relay-log-info-repository = TABLE
sync-master-info = 1
slave-parallel-workers = 2
binlog-checksum = CRC32
master-verify-checksum = 1
slave-sql-verify-checksum = 1
binlog-rows-query-log_events = 1
report-port = 3306
report-host = 192.168.1.66
四.配置系统服务
cp -af /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
#############################################
vi /etc/init.d/mysqld
修改两处位置:(46和47两行)
basedir=/usr/local/mysql
datadir=/data/mysql_data
#############################################
五.执行如下命令
chmod 755 /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig --level 345 mysqld on
六.初始化数据库
cd /usr/local/mysql
./scripts/mysql_install_db --user=mysql --defaults-file=/etc/my.cnf
vim /etc/profile
export MYSQL_HOME="/usr/local/mysql"
export PATH="$PATH:$MYSQL_HOME/bin"
保存退出
. /etc/profile
七.启动数据库
service mysqld start
如果出现了下面的错误:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
用下面的命令去解决,直接复制粘贴!
ln -s /data/mysql_data/mysql.sock /tmp/mysql.sock
MYSQL安装完成以后的配置:
mysqladmin -u root password 'root' #修改root用户密码,如果有问题mysqladmin: connect to server at 'localhost' failed
mysql -u root -p #登录mysql,需要输入密码
mysql>GRANT ALL PRIVILEGES ON . TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION; #允许root用户远程访问
mysql>FLUSH PRIVILEGES; #刷新权限
mysql>exit
删除匿名账户
UPDATE mysql.user set password=PASSWORD('your password') where user='';
FLUSH PRIVILEGES;