MySQL多例項安裝
阿新 • • 發佈:2020-07-22
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.socknice = 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