1. 程式人生 > >linux伺服器-LAMP安裝配置2-安裝mysql

linux伺服器-LAMP安裝配置2-安裝mysql

十、安裝mysql(mysql-5.7.13)

​1、到mysql官網獲取下載地址:

選擇linux通用版​​​:

複製下載連結:

​2、下載:

cd /home/src​​

3、安裝:

指定路徑:

​下載檔案所在路徑:/home/src

mysql安裝路徑:、/usr/local/mysql

mysql資料庫儲存路徑:/etc/mysql

日誌儲存路徑:/etc/log/mysql​

mkdir /etc/mysql​

cd /home/src​

tar zxvf ​mysql-5.7.13-linux-glibc2.5-x86_64.tar.gz//解壓完就是一個免安裝的mysql目錄了

mv mysql-5.7.13-linux-glibc2.5-x86_64 /usr/local/mysql//移動位置並重新命名為mysql

​新建mysql組:useradd -r -s /sbin/nologin -g mysql mysql -d /usr/local/mysql —新建msyql使用者禁止登入shell

改變目錄所有者:

​cd /usr/local/mysql

chown –R mysql .

chgrp –R mysql .

chown -R mysql /etc/mysql

配置引數:

bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/etc/mysql

注意:若出錯:bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory 解決:yum install libaio

注意:執行完會顯示:A temportary password is generated for [email protected]:​B/oiqs%,M2N*這個是臨時密碼,記錄下來後面有用

bin/mysql_ssl_rsa_setup --datadir=/etc/mysql​

修改系統配置檔案:

​cp support-files/my-default.cnf /etc/my.cnf

cp support-files/mysql.server /etc/init.d/mysql

配置/etc/init.d/mysql​檔案:

​vim /etc/init.d/mysql

修改下面內容:

basedir=/usr/local/mysql

datadir=/etc/mysql

配置my.cnf檔案:

​[client]

port = 3306 # 設定mysql客戶端連線服務端時預設使用的埠

socket = /usr/local/mysql/mysql.sock

default-character-set = utf8 # 設定mysql客戶端預設字符集

#character-set-server = utf8 #這裡會報錯,用上面那條代替

​[mysql]

no-auto-rehash

[mysqld]

port = 3306 #mysql服務端預設監聽的TCP/IP埠 ​

socket = /usr/local/mysql/mysql.sock

basedir = /usr/local/mysql # 基準路徑,其他路徑都相對於這個路徑

max_allowed_packet = 32M

datadir = /etc/mysql # mysql資料庫檔案所在目錄

explicit_defaults_for_timestamp = true

skip-ssl

secure-file-priv = NULL

lower_case_table_names = 1

back_log = 300

max_connections = 3000

max_connect_errors = 100

table_open_cache = 4096

external-locking = FALSE

sort_buffer_size = 16M

join_buffer_size = 16M

thread_cache_size = 16M

query_cache_size = 128M

query_cache_limit = 4M

ft_min_word_len = 8

thread_stack = 512K

transaction_isolation = REPEATABLE-READ

tmp_table_size = 128M

max_heap_table_size = 128M

long_query_time = 6

slow_query_log

slow_query_log_file = /etc/log/mysql/slow.log

[mysqldump]

quick

max_allowed_packet = 32M

[mysqld_safe]

open-files-limit = 8192

log-error = /etc/log/mysql/mysql_3306.err

#這裡的mysql_3306.err檔案要chown mysql /etc/log/mysql/mysql_3306.err 更改屬主,否則無法啟動

啟動mysql:bin/mysqld_safe --user=mysql & //在後臺掛起

登陸mysql:​bin/mysql --user=root –p 輸入之前的臨時密碼

​mysql> set password=password(‘123’);//修改root密碼為123

mysql>grant all privileges on . to [email protected]’%’ identified by ‘123’;//所有ip都能遠端訪問該伺服器上的mysql資料庫

​mysql> flush privileges;//生效

退出mysql:quit;

把mysql的命令配置到系統環境變數中,以後呼叫不用寫路徑:

​vim /etc/profile

最後一行加:export PATH=/usr/local/mysql/bin:$PATH

source /etc/profile //使修改生效

配置mysql開機啟動:

​chmod 755 /etc/init.d/mysql

​chkconfig --add mysql

​chkconfig --level 345 mysql on