MySQL多实例安装
Mysql数据库多实列安装
1.环境
操作系统:Ubuntu14.04
MySQL版本:mysql5.6
2.新建MySQL目录
mkdir -p /data/mysql8005/data mkdir /data/mysql8005/log mkdir /data/mysql8005/conf.d
3.建立MySQL配置文件
cp /etc/my.cnf /data/mysql8005/ vim /data/mysql8005/my.cnf [client] #设置sock位置 socket = /data/mysql8005/mysqld.sock [mysqld_safe] socket = /data/mysql8005/mysqd.sock nice = 0 [mysqld] user = mysql #设置pid文件为位置 pid-file = /data/mysql8005/mysqld.pid #设置sock文件位置 socket = /data/mysql8005/mysqld.sock #mysql监听端口 port = 8005 basedir = /usr #mysql数据库文件存放位置 datadir = /data/mysql8005/data tmpdir = /tmp lc-messages-dir = /usr/share/mysql character-set-client-handshake = FALSE character-set-server = utf8mb4 collation-server = utf8mb4_unicode_ci init_connect='SET NAMES utf8mb4' skip-external-locking innodb_strict_mode = 0 slave_skip_errors = 1062,1146 binlog_ignore_db = information_schema,performance_schema,mysql myisam_sort_buffer_size = 2048M tmp_table_size = 512M myisam_max_sort_file_size=30G key_buffer = 16M max_allowed_packet = 1024M thread_stack = 192K thread_cache_size = 8 myisam-recover = BACKUP max_connections = 5000 query_cache_limit = 1M query_cache_size = 16M #mysql日志存放位置 log_error = /data/mysql8005/log/err5.log server-id = 12 log_bin = mysql-my5bin.log expire_logs_days = 10 max_binlog_size = 100M #设置mysql目录位置 innodb_data_home_dir = /data/mysql8005 innodb_data_file_path=ibdata1:50M:autoextend innodb_file_per_table = 1 innodb_buffer_pool_size = 30720M innodb_log_file_size = 1024M innodb_log_buffer_size = 512M innodb_flush_log_at_trx_commit = 1 innodb_lock_wait_timeout = 50 [mysqldump] quick quote-names max_allowed_packet = 1024M [mysql] #no-auto-rehash # faster start of mysql but no tab completition default-character-set = utf8mb4 [isamchk] key_buffer = 16M #mysql配置文件目录,可以不配置 !includedir /data/mysql8005/conf.d/
3.授权MySQL读取权限
vim编辑/etc/apparmor.d/usr.sbin.mysqld文件,添加如下内容
添加完成后刷新apparmor配置:
service apparmor restart
4.初始化数据库
mysql_install_db --defaults-file=/data/mysql8005/my.cnf --basedir=/usr/ --datadir=/data/mysql8005/data --user=mysql
5.启动实列
mysqld_safe --defaults-file=/data/mysql8005/my.cnf --skip-grant-tables & #--skip-grant-tables是为了跳过密码验证,先通过安全模式启动实列修改密码 无密码登录数据库 mysql -S /data/mysql8005/mysqd.sock –P 8005 修改root密码 mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('Chz2018!QAZqwe@#$'); mysql>quit 启动实列数据库: mysqld_safe --defaults-file=/data/mysql8005/my.cnf & 关闭实列 mysqladmin -uroot -p –S /data/mysql8005/mysqd.sock shutdown password:******* 重新启动实列 mysqld_safe --defaults-file=/data/mysql8005/my.cnf &
6.FAQ
FAQ FATAL ERROR: Could not find my-default cnf, could not find my-default cnf, fata error my-default cnf, fatal error could not find my-default cnf, mysql_install_db my-default cnf error 解决办法 vim /usr/share/mysql/my-default.cnf [mysqld] sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES