下载mysql编译后的包,解压到/export/local/ (具体根据自己使用情况而定)下


一、添加mysql用户和用户组

1、groupadd mysql
2、useradd -r -g mysql mysql


二、mysql数据目录初始化

1、mkdir /data/mysql/data
2、chown -R mysql:mysql /data/mysql/data
3、/export/local/mysql/bin/mysqld --defaults-file=/etc/my_3700.cnf --initialize --user=mysql --basedir=/export/local/mysql --datadir=/data/mysql/data

##初始化
说明:--basedir 为mysql安装路径,这里是安装在/export/local/目录下
           --datadir 为mysql数据目录

重要:
此处需要注意记录生成的临时密码,如上文:GleB(RP14p


三、数据库配置与启动
/export/local/mysql/bin/mysqld_safe --defaults-file=/etc/my_3700.cnf &
说明:--defaults-file 指定数据库配置文件
配置(/etc/my_3700.cnf)样本:

[client]
port = 3700 #端口
socket = /tmp/mysql.sock #如果主机上运行了多个mysql,请注意区分开来
default-character-set=utf8

[mysql]
default-character-set=utf8

[mysqld]
server_id = 13000
port = 3700
user = mysql
character-set-server = utf8mb4
default_storage_engine = innodb
log_timestamps = SYSTEM
socket = /tmp/mysql.sock #如果主机上运行了多个mysql,请注意区分开来
basedir = /export/local/mysql #数据库安装目录
datadir = /data/mysql/data #数据库数据目录
pid-file = /data/mysql/data/mysql.pid #PID文件路径
max_connections = 10000
max_connect_errors = 10000
table_open_cache = 1024
max_allowed_packet = 128M
open_files_limit = 65535
lower_case_table_names = 1
innodb_buffer_pool_size = 1024M
innodb_file_per_table = 1
innodb_write_io_threads = 4
innodb_read_io_threads = 4
innodb_purge_threads = 2
innodb_flush_log_at_trx_commit = 1
innodb_log_file_size = 512M
innodb_log_files_in_group = 2
innodb_log_buffer_size = 16M
innodb_max_dirty_pages_pct = 80
innodb_lock_wait_timeout = 30
innodb_data_file_path = ibdata1:10M:autoextend
slow_query_log = 1
long_query_time = 1
log_error = /data/mysql/log/mysql-3700-error.log #日志路径
slow_query_log_file = /data/mysql/log/mysql-3700-slow.log
transaction-isolation=Read-Committed

log-bin = mysql-bin
innodb_flush_log_at_trx_commit = 1
binlog_ignore_db = mysql

lower_case_table_names=1      #不区分大小写,其实都是转换成小写
max_connect_errors=1000


四、以临时密码登录mysql,并重置密码

step 1: SET PASSWORD = PASSWORD('your new password');
step 2: ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;
step 3: flush privileges;


五、授权

GRANT ALL ON *.* TO 'root'@'%' IDENTIFIED BY 'your password';

flush privileges;