【安裝方式】
【部署-二進(jìn)制安裝】
[root@web02 ~]# useradd mysql -s /sbin/nologin -M
[root@web02 ~]# mkdir -p /server/tools
###官網(wǎng)下載
https://downloads.mysql.com/archives/community/
下載5.7.26版本,那個(gè)600M的,64位
###yum源地址
http://mirrors.163.com/mysql/Downloads/
【解壓】
[root@web02 /server/tools]# tar xzvf mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz
###改名
[root@web02 /application]# mv mysql-5.7.26-linux-glibc2.12-x86_64 /application/mysql_5.7.26
###做個(gè)軟連接,和nginx一個(gè)套路
[root@web02 /application]# ln -s mysql_5.7.26/ ./mysql
[root@web02 /application]# ls
mysql? mysql_5.7.26
[root@web02 /application]# ll
total 0
lrwxrwxrwx 1 root root? 13 Dec 26 20:19 mysql -> mysql_5.7.26/
drwxr-xr-x 9 root root 120 Dec 26 20:16 mysql_5.7.26
至此安裝結(jié)束科阎,不需要編譯攻询,相當(dāng)于windows綠色版,解壓完了直接用即可
【卸載centos7自帶的mariadb庫防止沖突】
[root@web02 ~]# rpm -qa mariadb-libs
mariadb-libs-5.5.44-2.el7.centos.x86_64
[root@web02 ~]# rpm -e --nodeps mariadb-libs
【修改my.cnf配置文件】
5.7.26的mysql沒有默認(rèn)的模板了搓幌,只能自己創(chuàng)建
[root@web02 ~]# vim /etc/my.cnf
[mysqld]
user = mysql
basedir = /application/mysql/
datadir = /application/mysql/data
socket = /tmp/mysql.sock
server_id = 1
port = 3306
log_error = /application/mysql/data/luoqi_mysql.err
[mysql]
socket = /tmp/mysql.sock
prompt = luoqi [\\d]>? ##提示符
【初始化數(shù)據(jù)庫】
###檢查mariadb是否已經(jīng)卸載干凈
[root@web02 ~]# rpm -qa mariadb-libs
###安裝mysql依賴包
[root@web02 ~]# yum install -y libaio-devel
###創(chuàng)建數(shù)據(jù)目錄
[root@web02 ~]# mkdir /application/mysql/data
###授權(quán)目錄mysql角色
[root@web02 ~]# chown -R mysql.mysql /application/mysql
坑,光給軟連接授權(quán)沒用伴逸,要給原始目錄做授權(quán)
[root@web02 ~]# chown -R mysql.mysql /application/mysql_5.7.26/
###初始化
[root@web02 ~]# /application/mysql/bin/mysqld --initialize-insecure --user=mysql \
--basedir=/application --datadir=/application/mysql/data
###參數(shù)解釋
--initialize-insecure 關(guān)閉安全策略
--initialize 開啟安全策略
--user=mysql msql用戶
--basedir=/application mysql根目錄
--datadir mysql數(shù)據(jù)目錄
###如果不提示說明OK伸蚯,提示warn可以忽略摩渺,但是有error就不行!
###檢測是否初始化成功
[root@web02 /application]# ll /application/mysql/data/
total 110632
-rw-r----- 1 mysql mysql? ? ? 56 Dec 26 21:06 auto.cnf
-rw-r----- 1 mysql mysql? ? ? 419 Dec 26 21:06 ib_buffer_pool
-rw-r----- 1 mysql mysql 12582912 Dec 26 21:06 ibdata1
-rw-r----- 1 mysql mysql 50331648 Dec 26 21:06 ib_logfile0
-rw-r----- 1 mysql mysql 50331648 Dec 26 21:06 ib_logfile1
-rw-r----- 1 mysql mysql? ? 1035 Dec 26 21:06 luoqi_mysql.err
drwxr-x--- 2 mysql mysql? ? 4096 Dec 26 21:06 mysql
drwxr-x--- 2 mysql mysql? ? 8192 Dec 26 21:06 performance_schema
drwxr-x--- 2 mysql mysql? ? 8192 Dec 26 21:06 sys
【啟動(dòng)mysql】
###制作C7systemctl管理服務(wù)
vim /etc/systemd/system/mysqld.service
----------------------------------------------------------------------------
[Unit]
Description=MySql Server by luoqi
After=network.target syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
ExecStart=/application/mysql/bin/mysqld --defaults-file=/etc/my.cnf
LimitNOFILE=5000
----------------------------------------------------------------------------
【啟動(dòng)服務(wù)】
[root@web02 /application]# systemctl start mysqld.service
[root@web02 /application]# systemctl enable mysqld.service
[root@web02 /application]# systemctl status mysqld.service
● mysqld.service - MySql Server by luoqi
? Loaded: loaded (/etc/systemd/system/mysqld.service; enabled; vendor preset: disabled)
? Active: active (running) since Sat 2020-12-26 22:50:33 CST; 6s ago
Main PID: 3912 (mysqld)
? CGroup: /system.slice/mysqld.service
? ? ? ? ? └─3912 /application/mysql/bin/mysqld --defaults-file=/etc/my.cnf
Dec 26 22:50:33 web02 systemd[1]: Started MySql Server by luoqi.
###查看端口
[root@web02 /application]# netstat -tlunp|grep 3306
tcp6? ? ? 0? ? ? 0 :::3306? ? ? ? ? ? ? ? :::*? ? ? ? ? ? ? ? ? ? LISTEN? ? ? 3912/mysqld
###配置環(huán)境變量
[root@web02 /application]# vim /etc/profile <<=添加如下內(nèi)容
export PATH=/application/mysql/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
[root@web02 /application]# . /etc/profile
###登陸成功剂邮!
[root@web02 ~]# mysql
Welcome to the MySQL monitor.? Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.26 MySQL Community Server (GPL)
Copyright (c) 2000, 2019, 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.
luoqi [(none)]>
【圖形化操作mysql】
下載Navicat,用ssh隧道連接即可
【錯(cuò)誤提示1】
###原因摇幻,用root用戶執(zhí)行的編譯安裝,mysql不建議用root用戶啟用mysql進(jìn)程
[root@web01 application]# /application/mysql/bin/mysqld
2020-12-28T01:27:20.453028Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2020-12-28T01:27:20.453143Z 0 [Note] --secure-file-priv is set to NULL. Operations related to importing and exporting data are disabled
2020-12-28T01:27:20.453169Z 0 [Note] /application/mysql/bin/mysqld (mysqld 5.7.30) starting as process 8869 ...
2020-12-28T01:27:20.455760Z 0 [ERROR] Fatal error: Please read "Security" section of the manual to find out how to run mysqld as root!
2020-12-28T01:27:20.455782Z 0 [ERROR] Aborting
2020-12-28T01:27:20.455799Z 0 [Note] Binlog end
2020-12-28T01:27:20.455845Z 0 [Note] /application/mysql/bin/mysqld: Shutdown complete
###解決方式1
[root@web01 application]# /application/mysql/bin/mysqld --user=mysql
###解決方式2
在my.cnf的[mysqld]模塊下添加user = mysql
【錯(cuò)誤2】
如果沒用systemctl管理挥萌,而是直接用mysqld啟動(dòng)绰姻,那么就會(huì)卡住不動(dòng),因?yàn)槭且粋€(gè)后臺(tái)進(jìn)程引瀑】裼螅可以用
mysqld & 后臺(tái)運(yùn)行即可
【錯(cuò)誤3】
mysql進(jìn)入數(shù)據(jù)庫發(fā)現(xiàn)沒有databases,因?yàn)槟阒付ǖ挠脩羰莔ysql憨栽,而進(jìn)入只有root用戶才能看到user表
但是用systemctl管理之后默認(rèn)mysql進(jìn)去就是root權(quán)限
【啟動(dòng)方式補(bǔ)充】
針對(duì)于mysql5.7.26版本除了systemctl管理也可以腳本啟動(dòng)帜矾,這個(gè)腳本在
[root@nfs01 app]# ll /app/mysql/support-files/mysql.server
-rwxr-xr-x 1 mysql mysql 10576 Apr 13? 2019 /app/mysql/support-files/mysql.server
后面跟 start|stop|restart即可啟動(dòng)mysql
【初始化數(shù)據(jù)庫安全參數(shù)補(bǔ)充】
如果加了--initialize-insecure,那么部署之后直接msyql -u root可以直接登錄
如果加了--initialize徒像,仔細(xì)看輸出會(huì)生成一組隨機(jī)密碼
[root@nfs01 app]# /app/mysql/bin/mysqld --initialize --user=mysql --basedir=/app/mysql --datadir=/data-mysql
2021-02-10T09:10:12.692639Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-02-10T09:10:12.827988Z 0 [Warning] InnoDB: New log files created, LSN=45790
2021-02-10T09:10:12.851360Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2021-02-10T09:10:12.912023Z 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: c838dabd-6b7f-11eb-9a5e-000c29f7b211.
2021-02-10T09:10:12.913725Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2021-02-10T09:10:12.915724Z 1 [Note] A temporary password is generated for root@localhost: 7IyoNsP(!Ue>
之后用這個(gè)默認(rèn)root密碼登錄進(jìn)mysql