首頁 >資料庫 >mysql教程 >Centos7在Linux下安裝Mysql5.7.19的教學(圖)

Centos7在Linux下安裝Mysql5.7.19的教學(圖)

黄舟
黄舟原創
2017-09-02 13:37:561832瀏覽

這篇文章主要介紹了Linux下Centos7安裝Mysql5.7.19的教學詳解,需要的朋友可以參考下

1.下載mysql

#2.選擇原始碼包,通用版點擊下載

#直接下載就可以了,不用登入

3.解壓縮編譯


#
tar -zxvf mysql-5.7.19.tar.gz
cd mysql-5.7.19.tar.gz

建立資料目錄  mkdir -p / data/mysql

先用cmake編譯,沒有這個指令需要先yum安裝


cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql/  #这个是编译安装之后的mysql目录所在地,可自行更改
-DMYSQL_DATADIR=/data/mysql/    #这个指向数据目录
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock
-DSYSCONFDIR=/usr/local/mysql-5.7/conf/
-DWITH_MYISAM_STORAGE_ENGINE=1
-DWITH_INNOBASE_STORAGE_ENGINE=1
-DWITH_BLACKHOLE_STORAGE_ENGINE=1
-DWITH_ARCHIVE_STORAGE_ENGINE=1
-DWITH_MEMORY_STORAGE_ENGINE=1
-DWITH_READLINE=1
-DMYSQL_TCP_PORT=3306
-DENABLED_LOCAL_INFILE=1
-DDEFAULT_CHARSET=utf8
-DDEFAULT_COLLATION=utf8_general_ci
-DMYSQL_USER=mysql
-DWITH_SSL=system
-DWITH_ZLIB=system -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/usr/local/boost #从MySQL 5.7.5开始Boost库是必需安装的

編譯之後make && make install  漫長的等待....之後就安裝完成了

安裝完成之後路徑/usr/local/ 下面會有一個目錄mysql,這個目錄就是我編譯安裝設定的路徑-


DCMAKE_INSTALL_PREFIX=/usr/local/mysql/

一般為了安全起見,我們都會建立一個mysql使用者和mysql群組,執行下列指令


#添加用户组
groupadd mysql
#添加用户mysql 到用户组mysql
useradd
-g mysql mysql

給予mysql權限


chown -R mysql:mysql mysql
#添加用户组
groupadd mysql
#添加用户mysql 到用户组mysql
useradd -g mysql mysql

給予mysql權限


#
chown -R mysql:mysql mysql

4.接下來設定啟動向,設定開機啟動

設定/ect/my.cnf,如果沒有my.cnf可自行新建新增,  僅供參考


[client]
ort = 3306
ocket = /tmp/mysql.sock
default-character-set = utf8mb4
[mysqld]
ort = 3306
ocket = /tmp/mysql.sock
asedir = /usr/local/mysql
datadir = /data/mysql
id-file = /data/mysql/mysql.pid
user = mysql
ind-address = 0.0.0.0
erver-id = 1
init-connect = 'SET NAMES utf8mb4'
character-set-server = utf8mb4
#skip-name-resolve
#skip-networking
ack_log = 300
max_connections = 1000
max_connect_errors = 6000
open_files_limit = 65535
table_open_cache = 128
max_allowed_packet = 4M
inlog_cache_size = 1M
max_heap_table_size = 8M
tmp_table_size = 16M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
ort_buffer_size = 8M
join_buffer_size = 8M
key_buffer_size = 4M
thread_cache_size = 8
query_cache_type = 1
query_cache_size = 8M
query_cache_limit = 2M
ft_min_word_len = 4
log_bin = mysql-bi
inlog_format = mixed
expire_logs_days = 30
log_error = /data/mysql/mysql-error.log
low_query_log = 1
long_query_time = 1
low_query_log_file = /data/mysql/mysql-slow.log
erformance_schema = 0
explicit_defaults_for_timestam
#lower_case_table_names = 1
kip-external-locking
default_storage_engine = InnoDB
#default-storage-engine = MyISAM
innodb_file_per_table = 1
innodb_open_files = 500
innodb_buffer_pool_size = 64M
innodb_write_io_threads = 4
innodb_read_io_threads = 4
innodb_thread_concurrency = 0
innodb_purge_threads = 1
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 2M
innodb_log_file_size = 32M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
ulk_insert_buffer_size = 8M
myisam_sort_buffer_size = 8M
myisam_max_sort_file_size = 10G
myisam_repair_threads = 1
interactive_timeout = 28800
wait_timeout = 28800
[mysqldump]
quick
max_allowed_packet = 16M
[myisamchk]
key_buffer_size = 8M
ort_buffer_size = 8M
read_buffer = 4M
write_buffer = 4M

接下來就執行初始化資料庫語句:

注意mysql_install_db 已經不再推薦使用了,建議改成mysqld –initialize 完成實例初始化。


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

這一步很重要,如果沒有初始化直接啟動資料庫會報錯

ERROR! The server quit without updating PID file (/data/mysql/ mysql.pid).

如果初始化失敗或報以下錯誤,就需要先清空你的/data/mysql目錄了,因為mysql目錄下面有資料所以初始化執行中止。

2017-08-29T13:39:47.241469Z 0 [ERROR] --initialize specified but the data directory has files in it. Aborting.2017-08-2913:39:47.241536Z [ERR

清空之後再重新初始化


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

接下來可以啟動mysql了


ervice mysqld start

登入測試


/usr/local/mysql/bin/mysql -uroot -

因為初始化--initialize-insecure 是預設沒有密碼的所以密碼不用輸入直接確定就行了;

#假如登入報錯


ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

檢查你啟動資料庫成功沒  可執行  ps -ef | grep mysql  看看行程是不是啟動狀態

空密碼不安全所以我們還要設定密碼,下面指令中的\"root\"就是設定密碼區域,我的密碼設定為root,可自行修改


[root@localhost local]# /usr/local/mysql/bin/mysql -e "grant all privileges on *.* to root@'127.0.0.1' identified by \"root\" with grant option;"[root@localhost local]# /usr/local/mysql/bin/mysql -e "grant all privileges on *.* to root@'localhost' identified by \"root\" with grant option;"

接下來再登入測試一次密碼修改成功沒有就完成囉!

總結

#

以上是Centos7在Linux下安裝Mysql5.7.19的教學(圖)的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn