一、什么是SQL?
- SQL,指结构化查询语言,全称是 Structured Query Language。可以访问和处理数据库。
二、二进制rpm安装mysql
[root@tong ~]# wget https://dev.mysql.com/get/mysql80-community-release-el7-2.noarch.rpm //获取MySQL源
--2019-03-04 12:48:28-- https://repo.mysql.com//mysql80-community-release-el7-2.noarch.rpm
Resolving repo.mysql.com (repo.mysql.com)... 104.127.195.16
Connecting to repo.mysql.com (repo.mysql.com)|104.127.195.16|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 25892 (25K) [application/x-redhat-package-manager]
Saving to: ‘mysql80-community-release-el7-2.noarch.rpm’
100%[=========================================================>] 25,892 --.-K/s in 0.08s
2019-03-04 12:48:29 (334 KB/s) - ‘mysql80-community-release-el7-2.noarch.rpm’ saved [25892/25892]
[root@tong ~]# md5sum mysql80-community-release-el7-2.noarch.rpm //验证获取的源
8039153c627b2eb0c0ce06d7dae9253f mysql80-community-release-el7-2.noarch.rpm
[root@tong ~]# yum -y install mysql80-community-release-el7-2.noarch.rpm //安装源
Loaded plugins: fastestmirror
Examining mysql80-community-release-el7-2.noarch.rpm: mysql80-community-release-el7-2.noarch
Marking mysql80-community-release-el7-2.noarch.rpm to be installed
........
Installed:
mysql80-community-release.noarch 0:el7-2
Complete!
[root@tong ~]# yum repolist
Loaded plugins: fastestmirror
base | 3.6 kB 00:00:00
epel | 4.7 kB 00:00:00
extras | 3.4 kB 00:00:00
mysql-connectors-community | 2.5 kB 00:00:00
mysql-tools-community | 2.5 kB 00:00:00
mysql80-community | 2.5 kB 00:00:00
updates | 3.4 kB 00:00:00
(1/10): base/7/x86_64/group_gz | 166 kB 00:00:00
(2/10): epel/x86_64/group_gz | 88 kB 00:00:00
(3/10): epel/x86_64/updateinfo | 960 kB 00:00:00
(4/10): extras/7/x86_64/primary_db | 180 kB 00:00:00
(5/10): base/7/x86_64/primary_db | 6.0 MB 00:00:00
(6/10): updates/7/x86_64/primary_db | 2.4 MB 00:00:00
(7/10): epel/x86_64/primary_db | 6.6 MB 00:00:00
(8/10): mysql-connectors-community/x86_64/primary_db | 37 kB 00:00:00
(9/10): mysql-tools-community/x86_64/primary_db | 54 kB 00:00:00
(10/10): mysql80-community/x86_64/primary_db | 53 kB 00:00:00
Determining fastest mirrors
repo id repo name status
base/7/x86_64 CentOS-7 10,019
epel/x86_64 Extra Packages for Enterprise Linux 7 - x86_64 12,902
extras/7/x86_64 CentOS-7 371
mysql-connectors-community/x86_64 MySQL Connectors Community 95
mysql-tools-community/x86_64 MySQL Tools Community 84
mysql80-community/x86_64 MySQL 8.0 Community Server 82
updates/7/x86_64 CentOS-7 1,103
repolist: 24,656
[root@tong ~]# yum repolist all |grep mysql
mysql-cluster-7.5-community/x86_64 MySQL Cluster 7.5 Community disabled
mysql-cluster-7.5-community-source MySQL Cluster 7.5 Community - disabled
mysql-cluster-7.6-community/x86_64 MySQL Cluster 7.6 Community disabled
mysql-cluster-7.6-community-source MySQL Cluster 7.6 Community - disabled
mysql-connectors-community/x86_64 MySQL Connectors Community enabled: 95
mysql-connectors-community-source MySQL Connectors Community - disabled
mysql-tools-community/x86_64 MySQL Tools Community enabled: 84
mysql-tools-community-source MySQL Tools Community - Sourc disabled
mysql-tools-preview/x86_64 MySQL Tools Preview disabled
mysql-tools-preview-source MySQL Tools Preview - Source disabled
mysql55-community/x86_64 MySQL 5.5 Community Server disabled
mysql55-community-source MySQL 5.5 Community Server - disabled
mysql56-community/x86_64 MySQL 5.6 Community Server disabled
mysql56-community-source MySQL 5.6 Community Server - disabled
mysql57-community/x86_64 MySQL 5.7 Community Server disabled
mysql57-community-source MySQL 5.7 Community Server - disabled
mysql80-community/x86_64 MySQL 8.0 Community Server enabled: 82
mysql80-community-source MySQL 8.0 Community Server - disabled
[root@tong ~]# yum -y install mysql-community-server
Loaded plugins: fastestmirror
........
Installed:
mysql-community-libs.x86_64 0:8.0.15-1.el7 mysql-community-libs-compat.x86_64 0:8.0.15-1.el7
mysql-community-server.x86_64 0:8.0.15-1.el7
Dependency Installed:
libaio.x86_64 0:0.3.109-13.el7 mysql-community-client.x86_64 0:8.0.15-1.el7
mysql-community-common.x86_64 0:8.0.15-1.el7
Dependency Updated:
postfix.x86_64 2:2.10.1-7.el7
Replaced:
mariadb-libs.x86_64 1:5.5.56-2.el7
Complete!
[root@tong ~]# systemctl start mysqld //启动
[root@tong ~]# systemctl enable mysqld //开机自启
[root@tong ~]# systemctl status mysqld //查看状态
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since Mon 2019-03-04 12:54:13 CST; 1min 45s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Main PID: 1422 (mysqld)
Status: "SERVER_OPERATING"
CGroup: /system.slice/mysqld.service
└─1422 /usr/sbin/mysqld
Mar 04 12:54:04 tong systemd[1]: Starting MySQL Server...
Mar 04 12:54:13 tong systemd[1]: Started MySQL Server.
[root@tong ~]# grep 'temporary password' /var/log/mysqld.log //查找登陆密码
2019-03-04T04:54:08.772728Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: cgYXkGXDv2_r //mysql初次登陆时有密码
[root@tong ~]# mysql -uroot -p'cgYXkGXDv2_r'
mysql: [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 8
Server version: 8.0.15
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.
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '111aaaQQQ!'; //修改登陆密码
Query OK, 0 rows affected (0.01 sec)
mysql> exit
Bye
[root@tong ~]# mysql -uroot -p //重新登陆
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.15 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.
mysql> show databases; //查看数据库
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
三、忘记密码?
可以用下面方法
[root@tong ~]# vim /etc/my.cnf
[root@tong ~]# systemctl restart mysqld //重新启动mysql
[root@tong ~]# mysql //可以免密登陆
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 8.0.15 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.
mysql> flush privileges; //首先刷新权限,不然修改会出错
Query OK, 0 rows affected (0.01 sec)
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'aaaAAA1!'; //重新设置密码
Query OK, 0 rows affected (0.01 sec)
mysql> exit
Bye
[root@tong ~]# vim /etc/my.cnf //删掉skip-grant-tables
[root@tong ~]# systemctl restart mysqld //重启数据库
[root@tong ~]# mysql -uroot -p //按照修改的密码登陆成功
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.15 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.
mysql>