centos7是最小化安裝。安裝在vm虛擬機上面。關於centos7的安裝請參考這裏html
[root@home ~]# rpm -qa|grep mariadb
mariadb-libs-5.5.56-2.el7.x86_64
[root@home ~]# rpm -e mariadb-libs-* --nodeps
[root@home ~]# rpm -qa|grep mariadb
複製代碼
將下載好的mysql安裝包使用filezilla上傳到/opt/packages/目錄下node
解壓mysql
[root@home ~]# cd /opt/packages/
[root@home packages]# mkdir mysql5.7.24
[root@home packages]# tar xvf mysql-5.7.24-1.el7.x86_64.rpm-bundle.tar -C mysql5.7.24/
mysql-community-common-5.7.24-1.el7.x86_64.rpm
mysql-community-minimal-debuginfo-5.7.24-1.el7.x86_64.rpm
mysql-community-embedded-compat-5.7.24-1.el7.x86_64.rpm
mysql-community-embedded-devel-5.7.24-1.el7.x86_64.rpm
mysql-community-embedded-5.7.24-1.el7.x86_64.rpm
mysql-community-libs-5.7.24-1.el7.x86_64.rpm
mysql-community-devel-5.7.24-1.el7.x86_64.rpm
mysql-community-server-5.7.24-1.el7.x86_64.rpm
mysql-community-libs-compat-5.7.24-1.el7.x86_64.rpm
mysql-community-client-5.7.24-1.el7.x86_64.rpm
mysql-community-server-minimal-5.7.24-1.el7.x86_64.rpm
mysql-community-test-5.7.24-1.el7.x86_64.rpm
[root@home packages]# ll mysql5.7.24/
總用量 585024
-rw-r--r--. 1 7155 31415 25398288 10月 5 2018 mysql-community-client-5.7.24-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415 280896 10月 5 2018 mysql-community-common-5.7.24-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415 3840412 10月 5 2018 mysql-community-devel-5.7.24-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415 46773880 10月 5 2018 mysql-community-embedded-5.7.24-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415 24078240 10月 5 2018 mysql-community-embedded-compat-5.7.24-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415 130082964 10月 5 2018 mysql-community-embedded-devel-5.7.24-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415 2272368 10月 5 2018 mysql-community-libs-5.7.24-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415 2116016 10月 5 2018 mysql-community-libs-compat-5.7.24-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415 56029544 10月 5 2018 mysql-community-minimal-debuginfo-5.7.24-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415 173096508 10月 5 2018 mysql-community-server-5.7.24-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415 15167212 10月 5 2018 mysql-community-server-minimal-5.7.24-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415 119909528 10月 5 2018 mysql-community-test-5.7.24-1.el7.x86_64.rpm
複製代碼
[root@home packages]# cd mysql5.7.24/
[root@home mysql5.7.24]# rpm -ivh mysql-community-common-5.7.24-1.el7.x86_64.rpm
[root@home mysql5.7.24]# rpm -ivh mysql-community-libs-5.7.24-1.el7.x86_64.rpm
[root@home mysql5.7.24]# rpm -ivh mysql-community-client-5.7.24-1.el7.x86_64.rpm
[root@home mysql5.7.24]# yum install -y net-tools perl
[root@home mysql5.7.24]# rpm -ivh mysql-community-server-5.7.24-1.el7.x86_64.rpm
複製代碼
[root@home mysql5.7.24]# mysqld --initialize --user=mysql
[root@home mysql5.7.24]# cat /var/log/mysqld.log
2020-03-24T13:25:15.230964Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2020-03-24T13:25:17.017911Z 0 [Warning] InnoDB: New log files created, LSN=45790
2020-03-24T13:25:17.269972Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2020-03-24T13:25:17.365912Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: e6f5e9e9-6dd2-11ea-a81b-000c2932737f.
2020-03-24T13:25:17.370666Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2020-03-24T13:25:17.414665Z 1 [Note] A temporary password is generated for root@localhost: *.ytw&qr+3N3
*.ytw&qr+3N3 就是生成的默認的密碼。
[root@home mysql5.7.24]# systemctl status mysqld
[root@home mysql5.7.24]# systemctl start mysqld
[root@home mysql5.7.24]# systemctl status mysqld
複製代碼
root@2020&*(
test!@#
admin@2020!@#
// 使用root登陸
[root@home mysql5.7.24]# mysql -uroot -p
// 修改root密碼
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'root@2020&*(';
// 建立只具備增刪改查的遠程登陸用戶test
mysql> create user 'test'@'%' identified by 'test!@#';
mysql> grant select, insert, update, delete on *.* to 'test'@'%';
mysql> flush privileges;
// 建立具備所有權限的admin用戶
mysql> create user 'admin'@'%' identified by 'admin@2020!@#';
mysql> grant all on *.* to 'admin'@'%' identified by 'admin@2020!@#';
mysql> flush privileges;
// 設置root遠程登陸權限【未執行】
mysql> grant all on *.* to 'root'@'%' identified by 'root@2020&*(';
mysql> flush privileges;
複製代碼
[root@home mysql5.7.24]# systemctl status mysqld
[root@home mysql5.7.24]# systemctl stop mysqld
複製代碼
具體能夠查看MySql5.7配置文件my.cnf設置。修改後的以下:程序員
[root@dev ~]# cat /etc/my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
# 設置表名不區分大小寫
lower_case_table_names=1
# 修改默認值,以達到5.6與5.7兼容的目的
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
# 數據庫默認字符集,主流字符集支持一些特殊表情符號(特殊表情符佔用4個字節)
character-set-server=utf8mb4
# 數據庫字符集對應一些排序等規則,注意要和character-set-server對應
collation-server=utf8mb4_general_ci
# 設置默認存儲引擎
default-storage-engine=INNODB
# 設置最大鏈接數
max_connections=1000
# 設置client鏈接mysql時的字符集,防止亂碼
init_connect='SET NAMES utf8mb4'
#TIMESTAMP若是沒有顯示聲明NOT NULL,容許NULL值
explicit_defaults_for_timestamp = true
複製代碼
[root@home mysql5.7.24]# systemctl start mysqld
複製代碼
[root@home mysql5.7.24]# firewall-cmd --zone=public --add-port=3306/tcp --permanent
success
[root@home mysql5.7.24]# firewall-cmd --reload
success
複製代碼
[root@home mysql5.7.24]# cd ..
[root@home packages]# rm -rf ./*
複製代碼
注意,不要刪除錯了。sql
使用navicat鏈接到MySQL上面測試鏈接,過程略。shell
注意事項:數據庫
- mysqld是mysql5.7的服務器進程,在初始化以前是不能啓動的。
- 進行配置文件中的設置時,能夠根據公司各自需求進行自定義設置。
- 安裝完成以後要刪除安裝包。
- utf8mb4字符集
- MySQL中的utf-8並非真正意義上的utf-8,它只能存儲1~3個字節長度的utf-8編碼,而存儲4個字節的必須用utf8mb4(mysql>=5.5.3支持),不然會出現亂碼。例如在微信管理系統中,消息文本使用了emoji表情:符號,必須使用utf8mb4進行儲存。 2.注意最大字符長度:以INNODB爲基礎,utf8最長VARCHAR(255),utf8mb4最長爲VARCHAR(191)。
- 要求在的mysql>=5.5.3版本,表、字段必須使用utf8mb4字符集和utf8mb4整理。
送你一本Java程序員運維技能手冊。在這centos