前言
近十年來,MySQL數(shù)據(jù)庫系統(tǒng)變的越來越流行了傻唾,幾乎成為各個互聯(lián)網(wǎng)應(yīng)用數(shù)據(jù)庫系統(tǒng)的標配。這里先介紹一下 MySQL 數(shù)據(jù)庫的安裝承耿,后續(xù)再做一些深度的主題冠骄。
準備安裝文件
現(xiàn)在 MySQL 最新版本已經(jīng)是 MySQL 8 了。所以我們這里就用 MySQL 8 來作為例子加袋。安裝 MySQL 8 的服務(wù)器是 CentOS 7 凛辣,IP 地址為 10.110.2.72 。
首先到官網(wǎng) https://dev.mysql.com/downloads/mysql/ 來下載對應(yīng)版本的 RPM 安裝包职烧,選擇如圖所示的版本扁誓。其中 Bundle 是一個包含了各種MySQL 其他組件的包防泵,免去了一個個單獨下載的繁瑣步驟。
安裝
我的操作系統(tǒng)是 CentOS 7 最小安裝的版本蝗敢。按照下面的操作步驟和順序進行择克,就可以將 MySQL 安裝到操作系統(tǒng)。
yum remove mariadb-libs
yum install perl
tar -xvf mysql-8.0.14-1.el7.x86_64.rpm-bundle.tar.gz
rpm -ivh mysql-community-common-8.0.14-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-8.0.14-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-compat-8.0.14-1.el7.x86_64.rpm
rpm -ivh mysql-community-embedded-compat-8.0.14-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-8.0.14-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-8.0.14-1.el7.x86_64.rpm
然后創(chuàng)建 mysql 的數(shù)據(jù)文件目錄
mkdir /data/mysql
mkdir /data/mysql/logs
chown -R mysql:mysql /data/mysql
配置
修改配置文件 /etc/my.cnf 如下所示
[mysqld]
server-id=72
port=38965
character-set-server=utf8mb4
default-time_zone='+8:00'
lower_case_table_names=1
max_connections=3000
max_connect_errors=100000
default_authentication_plugin=mysql_native_password
datadir=/data/mysql/data
socket=/data/mysql/mysql.sock
log-error=/data/mysql/logs/mysqld.log
pid-file=/data/mysql/mysqld.pid
long_query_time=1
slow_query_log = 1
slow_query_log_file=/data/mysql/logs/slow.log
[client]
port=38965
default-character-set=utf8mb4
socket=/data/mysql/mysql.sock
[mysql]
no-auto-rehash
default-character-set=utf8mb4
這里將 MySQL 的服務(wù)端口設(shè)置為 38965 前普,并且 server-id 設(shè)置為本機 ip 的最后一段 72 。
關(guān)閉 selinux,確保 getenforce 的值為 Permissive
setenforce 0
getenforce
Permissive
啟動
通過下面的命令啟動MySQL
systemctl start mysqld
如果沒有問題壹堰,查看 /data/mysql/logs/mysqld.log 文件內(nèi)容拭卿。
cat /data/mysql/logs/mysqld.log
2019-01-29T18:51:55.600096Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.13) initializing of server in progress as process 18964
2019-01-29T18:52:25.564666Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: ;-1wtd-t6jqE
2019-01-29T18:52:37.781510Z 0 [System] [MY-013170] [Server] /usr/sbin/mysqld (mysqld 8.0.13) initializing of server has completed
2019-01-29T18:52:41.606598Z 0 [Warning] [MY-010139] [Server] Changed limits: max_open_files: 10000 (requested 15000)
2019-01-29T18:52:41.606840Z 0 [Warning] [MY-010142] [Server] Changed limits: table_open_cache: 3495 (requested 4000)
2019-01-29T18:52:41.896630Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.13) starting as process 19012
2019-01-29T18:52:44.240940Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2019-01-29T18:52:44.320302Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.13' socket: '/data/mysql/mysql.sock' port: 38965 MySQL Community Server - GPL.
2019-01-29T18:52:44.458457Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: '/var/run/mysqld/mysqlx.sock' bind-address: '::' port: 33060
其中第二行表明生成了一個臨時的 root 密碼 ;-1wtd-t6jqE,可以用這個密碼來登錄 mysql 贱纠,但是登錄后首先需要修改掉這個初始的密碼峻厚,否則,不運行進行其他操作
[root@localhost ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 16
Server version: 8.0.14 MySQL Community Server - GPL
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> alter user 'root'@'localhost' identified by '新密碼';
mysql>
這樣谆焊,最新版本的 MySQL 8 就安裝好并且能夠運行了惠桃。