国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 數據庫 > MySQL > 正文

淺析CentOS6.8安裝MySQL8.0.18的教程(RPM方式)

2020-01-18 20:39:27
字體:
來源:轉載
供稿:網友

今天,記錄下在CentOS 6.8服務器上如何安裝MySQL 8.0.18,廢話不多說了,直接進入主題。

一、卸載CentOS 6.8自帶的MySQL

首先,卸載CentOS 6.8服務器上自帶的MySQL,在命令行中輸入如下命令查看CentOS 6.8服務器自帶的MySQL。

[root@binghe151 src]# rpm -qa | grep -i mysql    mysql-libs-5.1.73-7.el6.x86_64

可以看到,CentOS 6.8服務器中默認安裝了mysql-libs-5.1.73-7.el6.x86_64,接下來將mysql-libs-5.1.73-7.el6.x86_64卸載,如下所示。

[root@binghe151 src]# rpm -e mysql-libs-5.1.73-7.el6.x86_64 --nodeps [root@binghe151 src]# 

再次查看CentOS 6.8服務器自帶的MySQL,如下所示。

[root@binghe151 src]# rpm -qa | grep -i mysql[root@binghe151 src]# 

說明CentOS 6.8服務器自帶的MySQL卸載成功。

二、安裝MySQL依賴環境

正式安裝MySQL之前,首先需要安裝MySQL的依賴的基礎環境,如下所示。

yum -y install wget gcc-c++ ncurses ncurses-devel cmake make perl bison openssl openssl-devel gcc* libxml2 libxml2-devel curl-devel libjpeg* libpng* freetype* make gcc-c++ cmake bison-devel ncurses-devel bison perl perl-devel perl perl-devel net-tools* numactl* 

三、添加mysql用戶

在命令行執行如下命令添加mysql用戶。

groupadd mysqluseradd -g mysql mysql

四、下載并安裝MySQL的RPM安裝包

首先,在CentOS 6.8服務器的命令行執行如下命令下載MySQL 8.0.18的RPM安裝包。

wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.18-1.el6.x86_64.rpm-bundle.tar

接下來,查看下載的MySQL 8.0.18的RPM安裝包,如下所示

[root@binghe151 src]# lltotal 744876-rw-r--r--. 1 root root 762746880 Nov 18 14:32 mysql-8.0.18-1.el6.x86_64.rpm-bundle.tar

接下來,將下載的安裝包解壓,如下所示。

[root@binghe151 src]# tar xvf mysql-8.0.18-1.el6.x86_64.rpm-bundle.tar mysql-community-client-8.0.18-1.el6.x86_64.rpmmysql-community-test-8.0.18-1.el6.x86_64.rpmmysql-community-server-8.0.18-1.el6.x86_64.rpmmysql-community-libs-compat-8.0.18-1.el6.x86_64.rpmmysql-community-common-8.0.18-1.el6.x86_64.rpmmysql-community-devel-8.0.18-1.el6.x86_64.rpmmysql-community-libs-8.0.18-1.el6.x86_64.rpm

接下來,按照順序依次安裝

mysql-community-common-8.0.18-1.el6.x86_64.rpmmysql-community-libs-8.0.18-1.el6.x86_64.rpmmysql-community-client-8.0.18-1.el6.x86_64.rpmmysql-community-server-8.0.18-1.el6.x86_64.rpm

安裝時,需要嚴格按照上述順序進行安裝。

首先,安裝mysql-community-common-8.0.18-1.el6.x86_64.rpm,如下所示。

[root@binghe151 src]# rpm -ivh mysql-community-common-8.0.18-1.el6.x86_64.rpmwarning: mysql-community-common-8.0.18-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEYPreparing...    ########################################### [100%] 1:mysql-community-common ########################################### [100%]

接下來,安裝mysql-community-libs-8.0.18-1.el6.x86_64.rpm,如下所示。

[root@binghe151 src]# rpm -ivh mysql-community-libs-8.0.18-1.el6.x86_64.rpmwarning: mysql-community-libs-8.0.18-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEYPreparing...    ########################################### [100%] 1:mysql-community-libs ########################################### [100%]

接下來,安裝mysql-community-client-8.0.18-1.el6.x86_64.rpm,如下所示。

[root@binghe151 src]# rpm -ivh mysql-community-client-8.0.18-1.el6.x86_64.rpmwarning: mysql-community-client-8.0.18-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEYPreparing...    ########################################### [100%] 1:mysql-community-client ########################################### [100%]

最后,安裝mysql-community-server-8.0.18-1.el6.x86_64.rpm,如下所示。

[root@binghe151 src]# rpm -ivh mysql-community-server-8.0.18-1.el6.x86_64.rpmwarning: mysql-community-server-8.0.18-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEYPreparing...    ########################################### [100%] 1:mysql-community-server ########################################### [100%]

如果大家在安裝mysql-community-server-8.0.18-1.el6.x86_64.rpm的時候報錯,如下所示。

[root@binghe151 src]# rpm -ivh mysql-community-server-8.0.18-1.el6.x86_64.rpmwarning: mysql-community-server-8.0.18-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEYerror: Failed dependencies:  libnuma.so.1()(64bit) is needed by mysql-community-server-8.0.18-1.el6.x86_64  libnuma.so.1(libnuma_1.1)(64bit) is needed by mysql-community-server-8.0.18-1.el6.x86_64  libnuma.so.1(libnuma_1.2)(64bit) is needed by mysql-community-server-8.0.18-1.el6.x86_64

可以看到,缺少libnuma庫,執行如下命令安裝libnuma。

yum install numactl* -y

執行命令后,再次安裝mysql-community-server-8.0.18-1.el6.x86_64.rpm即可。

五、初始化MySQL數據

首先,來說一下MySQL官方對運行MySQL的限制。

在MySQL 8.x中,初始化數據需要確保數據庫目錄與文件的所有者為mysql登錄賬戶。如果以root身份運行mysqld服務,就需要確認一下,執行如下所示的包含有--user選項的命令:

shell> bin/mysqld --initialize --user=mysqlshell> bin/mysqld --initialize-insecure --user=mysql

如果是以mysql的賬戶登錄并執行程序的情況下,可以將--user選項從命令中去掉,如下所示。

shell> bin/mysqld --initializeshell> bin/mysqld --initialize-insecure

通過以上MySQL官方的對運行MySQL的限制,可以得出。

如果以root用戶身份登錄CentOS 6.8服務器,可以執行如下命令。

mysqld --initialize --user=mysqlmysqld --initialize-insecure --user=mysql

如果以mysql用戶身份登錄CentOS 6.8服務器,可以執行如下命令。

mysqld --initializemysqld --initialize-insecure

因為我這里使用的是root賬戶登錄CentOS 6.8服務器,所以,初始化數據庫時,我執行的是如下命令。

mkdir -p /usr/local/mysqlchown -R mysql.mysql /usr/local/mysqlmysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

注意:這里,我在執行mysqld --initialize命令時,指定了MySQL的安裝目錄。 在MySQL的安裝過程中,建議指定MySQL的安裝目錄。當/usr/local/mysql目錄下存在data目錄時,會初始化失敗,必須確保/usr/local/mysql下沒有data目錄。

六、啟動MySQL

在CentOS 6.8服務器命令行輸入如下命令啟動MySQL服務。

[root@binghe151 src]# service mysqld startStarting mysqld: [ OK ]

啟動MySQL時,會為MySQL的root賬戶生成臨時登錄密碼,這個密碼可以在/var/log/mysqld.log 文件中查看,使用vim編輯器打開/var/log/mysqld.log 文件,如下所示。

vim /var/log/mysqld.log 2019-11-18T08:16:08.162464Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.18) initializing of server in progress as process 21112019-11-18T08:16:12.451542Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: -8cagKkdK#5G2019-11-18T08:17:13.269505Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.18) starting as process 23782019-11-18T08:17:16.568836Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.2019-11-18T08:17:16.642494Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.18' socket: '/var/lib/mysql/mysql.sock' port: 3306 MySQL Community Server - GPL.2019-11-18T08:17:16.652000Z 7 [Warning] [MY-013360] [Server] Plugin sha256_password reported: ''sha256_password' is deprecated and will be removed in a future release. Please use caching_sha2_password instead'2019-11-18T08:17:16.801986Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: '/var/run/mysqld/mysqlx.sock' bind-address: '::' port: 33060

找到如下一行代碼。

2019-11-18T08:16:12.451542Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: -8cagKkdK#5G

可以看到,啟動MySQL時生成的臨時登錄密碼為-8cagKkdK#5G。

七、登錄MySQL

使用臨時密碼登錄MySQL,如下所示。

[root@binghe151 src]# mysql -uroot -p-8cagKkdK#5Gmysql: [Warning] Using a password on the command line interface can be insecure.Welcome to the MySQL monitor. Commands end with ; or /g.Your MySQL connection id is 9Server version: 8.0.18Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '/h' for help. Type '/c' to clear the current input statement.mysql> 

此時,在MySQL命令行執行SQL語句報錯,要求重置密碼,如下所示。

mysql> SHOW DATABASES;ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.mysql> use mysql;ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.mysql> 

接下來,修改MySQL的root賬戶密碼,如下所示。

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'root';Query OK, 0 rows affected (0.03 sec)mysql> FLUSH PRIVILEGES;Query OK, 0 rows affected (0.00 sec)

接下來,在MySQL命令行輸入exit命令退出MySQL。使用修改后的root密碼重新登錄MySQL,如下所示。

mysql> exitBye[root@binghe151 src]# mysql -uroot -prootmysql: [Warning] Using a password on the command line interface can be insecure.Welcome to the MySQL monitor. Commands end with ; or /g.Your MySQL connection id is 10Server version: 8.0.18 MySQL Community Server - GPLCopyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '/h' for help. Type '/c' to clear the current input statement.mysql> 

說明,MySQL的root賬戶密碼修改成功。

接下來,再次在MySQL命令行執行SQL語句,如下所示。

mysql> SHOW DATABASES;+--------------------+| Database   |+--------------------+| information_schema || mysql    || performance_schema || sys    |+--------------------+4 rows in set (0.36 sec)mysql> USE mysql;Reading table information for completion of table and column namesYou can turn off this feature to get a quicker startup with -ADatabase changedmysql>

可以看到,修改MySQL的root賬戶密碼后,可以在MySQL命令行正確執行SQL語句。

八、使用rpm安裝MySQL的默認目錄

1、數據庫目錄

/var/lib/mysql/

2、配置文件

/usr/share/mysql(mysql.server命令及配置文件)

3、相關命令

/usr/bin(mysqladmin mysqldump等命令)

4、啟動腳本

/etc/rc.d/init.d/(啟動腳本文件mysql的目錄)

九、配置my.cnf文件

MySQL 8.0默認沒有my.cnf,可以手動在/etc目錄下創建my.cnf文件,如果是以如下指定MySQL目錄的命令初始化數據。

mkdir -p /usr/local/mysqlchown -R mysql.mysql /usr/local/mysqlmysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data則可以將my.cnf文件配置成如下所示。[client]port = 3306#根據實際情況調整mysql.sock配置socket = /tmp/mysql.sock[mysqld]#Mysql服務的唯一編號 每個mysql服務Id需唯一server-id = 1#服務端口號 默認3306port = 3306#mysql安裝根目錄basedir = /usr/local/mysql#mysql數據文件所在位置datadir = /usr/local/mysql/data#pidpid-file = /usr/local/mysql/mysql.pid#設置socke文件所在目錄socket = /tmp/mysql.sock#設置臨時目錄tmpdir = /tmp# 用戶user = mysql# 允許訪問的IP網段bind-address = 0.0.0.0# 跳過密碼登錄#skip-grant-tables#主要用于MyISAM存儲引擎,如果多臺服務器連接一個數據庫則建議注釋下面內容skip-external-locking#只能用IP地址檢查客戶端的登錄,不用主機名skip_name_resolve = 1#事務隔離級別,默認為可重復讀,mysql默認可重復讀級別(此級別下可能參數很多間隙鎖,影響性能)transaction_isolation = READ-COMMITTED#數據庫默認字符集,主流字符集支持一些特殊表情符號(特殊表情符占用4個字節)character-set-server = utf8mb4#數據庫字符集對應一些排序等規則,注意要和character-set-server對應collation-server = utf8mb4_general_ci#設置client連接mysql時的字符集,防止亂碼init_connect='SET NAMES utf8mb4'#是否對sql語句大小寫敏感,1表示不敏感lower_case_table_names = 1#最大連接數max_connections = 400#最大錯誤連接數max_connect_errors = 1000#TIMESTAMP如果沒有顯示聲明NOT NULL,允許NULL值explicit_defaults_for_timestamp = true#SQL數據包發送的大小,如果有BLOB對象建議修改成1Gmax_allowed_packet = 128M#MySQL連接閑置超過一定時間后(單位:秒)將會被強行關閉#MySQL默認的wait_timeout 值為8個小時, interactive_timeout參數需要同時配置才能生效interactive_timeout = 1800wait_timeout = 1800#內部內存臨時表的最大值 ,設置成128M。#比如大數據量的group by ,order by時可能用到臨時表,#超過了這個值將寫入磁盤,系統IO壓力增大tmp_table_size = 134217728max_heap_table_size = 134217728#禁用mysql的緩存查詢結果集功能#后期根據業務情況測試決定是否開啟#大部分情況下關閉下面兩項query_cache_size = 0query_cache_type = 0#數據庫錯誤日志文件log_error = error.log#慢查詢sql日志設置slow_query_log = 1slow_query_log_file = slow.log#檢查未使用到索引的sqllog_queries_not_using_indexes = 1#針對log_queries_not_using_indexes開啟后,記錄慢sql的頻次、每分鐘記錄的條數log_throttle_queries_not_using_indexes = 5#作為從庫時生效,從庫復制中如何有慢sql也將被記錄log_slow_slave_statements = 1#慢查詢執行的秒數,必須達到此值可被記錄long_query_time = 8#檢索的行數必須達到此值才可被記為慢查詢min_examined_row_limit = 100#mysql binlog日志文件保存的過期時間,過期后自動刪除expire_logs_days = 5

總結

以上所述是小編給大家介紹的CentOS6.8安裝MySQL8.0.18的教程(RPM方式),希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對武林網網站的支持!如果你覺得本文對你有幫助,歡迎轉載,煩請注明出處,謝謝!

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 九龙城区| 邵阳县| 平远县| 临城县| 五河县| 晋中市| 保亭| 宿州市| 永德县| 宁蒗| 车险| 铜川市| 西贡区| 冕宁县| 墨竹工卡县| 旺苍县| 巴东县| 黔南| 偃师市| 宜兰县| 洱源县| 鱼台县| 大足县| 青海省| 墨竹工卡县| 瑞昌市| 成安县| 沾化县| 宁陕县| 敦煌市| 阜平县| 朝阳区| 白玉县| 河西区| 万州区| 鄂尔多斯市| 安庆市| 万源市| 海城市| 镇平县| 双城市|