一相味、環(huán)境準(zhǔn)備
1.1 關(guān)閉防火墻
#停止防火墻
systemctl stop firewalld.service
#禁止firewall開機(jī)啟動(dòng)
systemctl disable firewalld.service
#查看默認(rèn)防火墻狀態(tài)
firewall-cmd--state
1.2 安裝必備軟件
#更新軟件包
yum -y update
#安裝上傳下載lszrz
yum -y install lszrz
#安裝wget
yum -y install wget
二、安裝mysql過(guò)程
1.1 檢查是否安裝MySQL,如果安裝 卸載之
rpm -qa |grep mysql
yum? remove mysql*
1.2 檢查是否安裝MariaDB,如果安裝 卸載之(重要)
rpm -qa |grep mariadb
yum remove mariadb*
1.3 wget下載mysql5.7.26
#建立目錄用來(lái)放需要安裝的軟件(自己習(xí)慣來(lái)建目錄)
mkdir -p /app
#下載????
wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz
有點(diǎn)慢睦柴,可以到官網(wǎng)下載,在rz? -y上傳
1.4? 解壓并且改名為mysql
[root@mysql app]# ls
mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz
[root@mysql app]# tar -xzvf mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz
[root@mysql app]# mv mysql-5.7.26-linux-glibc2.12-x86_64/ mysql
1.5 修改環(huán)境變量
[root@mysql app]# vi /etc/profile
#在最后添加即可
exportPATH=/app/mysql/bin:$PATH
#生效
[root@mysql app]# source /etc/profile
1.6? 建立mysql用戶和組
useradd mysql
1.7 創(chuàng)建相關(guān)目錄并修改權(quán)限
[root@mysql app]# mkdir /data/mysql -p
[root@mysql app]# chown -R mysql.mysql /app/*
[root@mysql app]# chown -R mysql.mysql /data/*
1.8 初始化數(shù)據(jù)庫(kù)
[root@mysql mysql]# rm -rf /data/mysql/*
[root@mysql mysql]# mysqld --initialize-insecure --user=mysql --basedir=/app/mysql --datadir=/data/mysql
2019-08-20T03:29:54.126839Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-08-20T03:29:55.345568Z 0 [Warning] InnoDB: New log files created, LSN=45790
2019-08-20T03:29:55.536508Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2019-08-20T03:29:55.617830Z 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: c77fff90-c2fa-11e9-bb4a-080027383c74.
2019-08-20T03:29:55.624489Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2019-08-20T03:29:55.627494Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
1.9 修改添加配置文件my.cnf
[root@mysql tmp]# vi /etc/my.cnf
[client]
port = 3306
socket = /tmp/mysql.sock
[mysqld]
user=mysql
basedir=/app/mysql
datadir=/data/mysql
server_id=1
port=3306
socket=/tmp/mysql.sock
tmpdir? = /tmp
skip_name_resolve = 1
character-set-server = utf8mb4
collation-server = utf8mb4_general_ci
init_connect='SET NAMES utf8mb4'
lower_case_table_names = 1
max_connections = 400
max_connect_errors = 1000
interactive_timeout = 1800
wait_timeout = 1800
tmp_table_size = 134217728
max_heap_table_size = 134217728
log_error = /tmp/error.log
[mysql]
socket=/tmp/mysql.sock
prompt=3306 [\\d]>
1.10 使用systemd管理mysql
[root@mysql mysql]# vi /etc/systemd/system/mysqld.service
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
ExecStart=/app/mysql/bin/mysqld --defaults-file=/etc/my.cnf
LimitNOFILE = 5000
systemctl start/stop/restart/status mysqld
1.11 簡(jiǎn)單使用
#直接mysql命令進(jìn)入(此時(shí)密碼為空)
[root@mysql mysql]# 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.
#用戶信息? descmysql.user;
5.6版本:
select user,password,hostfrommysql.user;
5.7中用戶基本信息
3306 [(none)]>select user,authentication_string,host from mysql.user;
+---------------+-------------------------------------------+-----------+
| user? ? ? ? ? | authentication_string? ? ? ? ? ? ? ? ? ? | host? ? ? |
+---------------+-------------------------------------------+-----------+
| root? ? ? ? ? |? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? | localhost |
| mysql.session | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | localhost |
| mysql.sys? ? | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | localhost |
+---------------+-------------------------------------------+-----------+
3 rows in set (0.00 sec)
#修改密碼
[root@mysql mysql]# mysqladmin -uroot -p password '*******';
Enter password:
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety
#查看連接線程情況
3306 [(none)]>show processlist;
+----+------+-----------+------+---------+------+----------+------------------+
| Id | User | Host? ? ? | db? | Command | Time | State? ? | Info? ? ? ? ? ? |
+----+------+-----------+------+---------+------+----------+------------------+
| 10 | root | localhost | NULL | Query? |? ? 0 | starting | show processlist |
+----+------+-----------+------+---------+------+----------+------------------+
1 row in set (0.00 sec)
1.12 外部第三方管理軟件連接(SQLyog)
數(shù)據(jù)庫(kù)IP地址為 192.168.0.11 不能連接
#查看授權(quán)
3306 [(none)]>show grants for root@'192.168.0.%';
ERROR 1141 (42000): There is no such grant defined for user 'root' on host '192.168.0.%'
#主要是由于用戶和權(quán)限管理的問題翘盖,后面配置
1.13 用戶
#用戶的增刪改查
3306 [(none)]>create user victor@'192.168.0.%' identified by 'victor';
Query OK, 0 rows affected (0.00 sec)
3306 [(none)]>desc mysql.user;
3306 [(none)]>select user ,host ,authentication_string from mysql.user;
------
3306 [(none)]>alter user victor@'192.168.0.%' identified by '123456';
Query OK, 0 rows affected (0.00 sec)
3306 [(none)]>drop user victor@'192.168.0.%';
Query OK, 0 rows affected (0.00 sec)
1.14 權(quán)限管理
#先創(chuàng)建test 用戶
3306 [(none)]>create user test@'192.168.0.%' identified by 'test';
Query OK, 0 rows affected (0.00 sec)
#分配test用戶權(quán)限
3306 [(none)]>grant all on *.* to 'test'@'192.168.0.%';
Query OK, 0 rows affected (0.00 sec)
#用SQLyog連接?
ip地址:
192.168.0.11
用戶名
test
密碼
test
#權(quán)限介紹
ALL:SELECT,INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER, CREATE TABLESPACEALL : 以上所有權(quán)限澎嚣,一般是普通管理員擁有的withgrant option:超級(jí)管理員才具備的,給別的用戶授權(quán)的功能
#查看授權(quán)
3306 [(none)]>show grants for test@'192.168.0.%';
+-----------------------------------------------------+
| Grants for test@192.168.0.%? ? ? ? ? ? ? ? ? ? ? ? |
+-----------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'test'@'192.168.0.%' |
+-----------------------------------------------------+
1 row in set (0.00 sec)
#回收授權(quán)
revoke delete on *.*? from test@'192.168.0.%'榆鼠;