第一次在自己虛機上安裝mysql 中間碰到很多問題 在這里記下來,分享一下。
linux centOS 6
mysql版本 mysql-5.7.19-linux-glibc2.12-x86_64.tar.gz
1、groupadd mysql ## 添加一個mysql組
2、useradd -r -g mysql mysql ## 添加一個用戶
3、解壓縮下載的包,tar -xzvf /usr/local/mysql-5.7.13-linux-glibc2.5-x86_64.tar.gz
4、mv /usr/local/mysql-5.7.13-linux-glibc2.5-x86_64 /usr/local/mysql ##重命名
解壓后目錄:
5、mkdir /usr/local/mysql/data ## 默認是沒有這個文件夾得 用來放數據
6、chown -R mysql:mysql ./ ##進入mysql包中, 給這個包授權 給mysql
7、chgrp -R mysql:mysql ./ ##進入mysql包中
8、bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data ##進入mysql文件名 basedir 為mysql 的路徑, datadir 為mysql的 data 包,里面 存放着mysql自己的包, 如user
網上很多教程mysql_install_db 方式安裝的,我剛開始也是這么安裝,各種報錯、失敗,mysql_install_db 命令不推薦、按上面的命令來就好
此處需要注意記錄生成的臨時密碼,如上文:YLi>7ecpe;YP
9、bin/mysql_ssl_rsa_setup --datadir=/usr/local/mysql/data
10、進入mysql support-files
11、cp my-default.cnf /etc/my.cnf
發現這個版本就沒有my-default
這個是時候我們自己創建一個(內部代碼如圖): 重點下面兩個socket(紅色)對應的值必須一致,不然啟動以后鏈接不上
#dvice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.
[mysqld]
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
# 一般配置選項
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
port = 3306
#socket = /temp/mysqld.sock
socket = /var/run/mysqld/mysqld.sock
character-set-server=utf8
#下面是可選項,要不要都行,如果出現啟動錯誤,則全部注釋掉,保留最基本的配置選項,然后嘗試添加某些配置項后啟動,檢測配置項是否有誤
back_log = 300
max_connections = 3000
max_connect_errors = 50
table_open_cache = 4096
max_allowed_packet = 32M
#binlog_cache_size = 4M
max_heap_table_size = 128M
read_rnd_buffer_size = 16M
sort_buffer_size = 16M
join_buffer_size = 16M
thread_cache_size = 16
query_cache_size = 128M
query_cache_limit = 4M
ft_min_word_len = 8
thread_stack = 512K
transaction_isolation = REPEATABLE-READ
tmp_table_size = 128M
#log-bin=mysql-bin
long_query_time = 6
server_id=1
innodb_buffer_pool_size = 1G
innodb_thread_concurrency = 16
innodb_log_buffer_size = 16M
innodb_log_file_size = 512M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
innodb_file_per_table = on
[mysqldump]
quick
max_allowed_packet = 32M
[mysql]
no-auto-rehash
socket = /var/run/mysqld/mysqld.sock
default-character-set=utf8
safe-updates
[myisamchk]
key_buffer = 16M
sort_buffer_size = 16M
read_buffer = 8M
write_buffer = 8M
[mysqlhotcopy]
interactive-timeout
[mysqld_safe]
open-files-limit = 8192
[client]
loose-default-character-set = utf8
12、cp mysql.server /etc/init.d/mysql
13、vim /etc/init.d/mysql ##修改basedir= 自己的路徑 修改datadir= 自己的路徑
14、bin/mysqld_safe --user=mysql & ## 啟動mysql
13、./mysql -uroot -p ##bin目錄下
14、 輸入臨時密碼
15、修改MySQL的root密碼
此時mysql只有本地localhost可以訪問
16 修改可遠程訪問
重啟MySQL服務
此時本地可以正常使用MySQL
測試遠程連接
有的系統無法生成:/var/run/mysqld 匯報 如下錯誤:
mysqld_safe Directory '/var/run/mysqld' for UNIX socket file don't exists
The server quit without updating PID file (/usr/local/mysql/data/mysql.pid)
解決辦法 :
mkdir /var/run/mysqld
chown -R mysql:mysql /var/run/mysqld
chmod 755 /var/run/mysqld
再啟動mysql就可以了