在oracle官网下载mysql-advanced-5.6.26-linux-glibc2.5-x86_64.tar.gz,本例使用自定义目录安装在/u01/app/mysql-5.6.26下,此目录根据实际需要适应调整
一. 文件下载到服务器/u01/app目录下
cd /u01/app
tar zxvf mysql-advanced-5.6.26-linux-glibc2.5-x86_64.tar.gz
mv mysql-advanced-5.6.26-linux-glibc2.5-x86_64 mysql-5.6.26
二.创建mysql组和用户
groupadd -g 1000 mysql
useradd -u 1000 -g mysql mysql
三.目录权限分配
chmod +w /u01/app/mysql-5.6.26
chown -R mysql:mysql /u01/app/mysql-5.6.26
mkdir -p /u01/app/mysql-5.6.26/data
chown -R mysql:mysql /u01/app/mysql-5.6.26/data
mkdir -p /u01/app/mysql-5.6.26/log
chown -R mysql:mysql /u01/app/mysql-5.6.26/log
四.配置文件拷贝到系统目录下
cd mysql-5.6.26/support-files/
cp my-default.cnf /etc/my.cnfcp mysql.server /etc/init.d/mysqld
五. 配置调整,启动MySQL 5.6.26
1. 若有需要请先修改 mysql 的配置 my.cnf
vi /etc/my.cnf
[client] 配置为
default-character-set = utf8
port = 3306
socket = /u01/app/mysql-5.6.26/mysql.sock
[mysqld] 配置为
character_set_server = utf8
basedir = /u01/app/mysql-5.6.26
datadir = /u01/app/mysql-5.6.26/data
log-error = /u01/app/mysql-5.6.26/log/mysql_error.log
pid-file = /u01/app/mysql-5.6.26/mysql.pid
port = 3306
server_id = 1
socket = /u01/app/mysql-5.6.26/mysql.sock
max_connections = 1000
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
innodb_buffer_pool_size = 1024M
innodb_log_file_size = 256M
innodb_log_buffer_size = 16M
innodb_io_capacity = 200
# default_table_type = InnoDB
log-bin=mysql-bin
slow-query-log = /u01/app/mysql-5.6.26/log/mysql_slow.log
long_query_time = 5
lower_case_table_names=1
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
--其中内存部分配置根据服务器提供资源适应性调整
2.mysql 初始化安装
chmod +x /u01/app/mysql-5.6.26/scripts/mysql_install_db
/u01/app/mysql-5.6.26/scripts/mysql_install_db \
--defaults-file=/etc/my.cnf \
--basedir=/u01/app/mysql-5.6.26/ \
--datadir=/u01/app/mysql-5.6.26/data \
--user=mysql
3. 将 mysql 加入开机启动
chmod +x /etc/init.d/mysqld
vi /etc/init.d/mysqld (编辑此文件,查找并修改以下变量内容:)
basedir=/u01/app/mysql-5.6.26
datadir=/u01/app/mysql-5.6.26/data
chkconfig --add mysqld
chkconfig --level 345 mysqld on
4. 启动 mysql
service mysqld start
5. 配置访问帐号root
/u01/app/mysql-5.6.26/bin/mysqladmin -uroot password zdsoft
/u01/app/mysql-5.6.26/bin/mysql -uroot -p
mysql>use mysql;
mysql>GRANT ALL PRIVILEGES ON *.* TO root@'%' IDENTIFIED BY 'zdsoft' with GRANT OPTION;
mysql>update user set password=password('zdsoft'); --所有用户都密码更新
mysql>FLUSH PRIVILEGES;
mysql>quit;
6.为方便mysql操作,设置mysql用户的环境变量
su - mysql
vi ~/.bash_profile
--加入以下内容
MYSQL_HOME=/u01/app/mysql-5.6.26
PATH=$PATH:$HOME/bin:$MYSQL_HOME/bin