一、MySQL简介
MySQL是一个关系型数据库管理系统,由瑞典MySQL AB公司开发,属于Oracle旗下产品。MySQL是最流行的关系型数据库管理系统之一,在WEB应用方面,MySQL是最好的RDBMS(Relational Database Management System,关系数据库管理系统)应用软件之一。
MySQL是一种关系型数据库管理系统,关系数据库将数据保存在不同的表中,而不是将所有数据放在一个大仓库内,这样就增加了速度并提高了灵活性。
MySQL所使用的SQL语言是用于访问数据库的最常用标准化语言。MySQL软件采用了双授权政策,分为社区版和商业版,由于其体积小、速度快、总体拥有成本低,尤其是开放源码这一特点,一般中小型和大型网站的开发都选择MySQL作为网站数据库。
二、Yum安装MySQL
1、配置清华大学Yum源
[root@localhost ~]# vim /etc/yum.repos.d/mysql-community.repo
[mysql-connectors-community]
name=MySQL Connectors Community
baseurl=https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-connectors-community-el7-$basearch/
enabled=1
gpgcheck=1
gpgkey=https://repo.mysql.com/RPM-GPG-KEY-mysql
\[mysql-tools-community\]
name=MySQL Tools Community
baseurl=https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-tools-community-el7-$basearch/
enabled=1
gpgcheck=1
gpgkey=https://repo.mysql.com/RPM-GPG-KEY-mysql
\[mysql-5.7-community\]
name=MySQL 5.7 Community Server
baseurl=https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-5.7-community-el7-$basearch/
enabled=1
gpgcheck=0
gpgkey=https://repo.mysql.com/RPM-GPG-KEY-mysql
2、安装MySQL-5.7
[root@localhost ~]# yum -y install mysql-community-server
3、启动MySQL
[root@localhost ~]# systemctl start mysqld
4、登录MySQL
1)查看初始化后生成的密码
[root@localhost ~]# grep 'password' /var/log/mysqld.log
2022-12-14T07:48:14.697319Z 1 [Note] A temporary password is generated for root@localhost: j!#kVpr6_e:!
2)登录MySQL
[root@localhost ~]# mysql -uroot -p'j!#kVpr6_e:!'
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 6
Server version: 5.7.40
Copyright (c) 2000, 2022, Oracle and/or its affiliates.
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.
初始化后需重置密码才能执行sql
mysql> set password=password('Aa123456@!');
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> select version();
+-----------+
| version() |
+-----------+
| 5.7.40 |
+-----------+
1 row in set (0.00 sec)
三、RPM包安装MySQL
1、下载rpm包
[root@localhost ~]# wget https://repo.huaweicloud.com/mysql/Downloads/MySQL-5.7/mysql-5.7.38-1.el7.x86_64.rpm-bundle.tar
2、解压
[root@localhost ~]# tar xf mysql-5.7.38-1.el7.x86_64.rpm-bundle.tar
[root@localhost ~]# ls -l
total 1083052
-rw-------. 1 root root 1260 Jun 22 23:55 anaconda-ks.cfg
-rw-r--r-- 1 root root 554516480 Mar 23 2022 mysql-5.7.38-1.el7.x86_64.rpm-bundle.tar
-rw-r--r-- 1 7155 31415 28991900 Mar 23 2022 mysql-community-client-5.7.38-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415 318868 Mar 23 2022 mysql-community-common-5.7.38-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415 4363096 Mar 23 2022 mysql-community-devel-5.7.38-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415 47993516 Mar 23 2022 mysql-community-embedded-5.7.38-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415 23315792 Mar 23 2022 mysql-community-embedded-compat-5.7.38-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415 132675656 Mar 23 2022 mysql-community-embedded-devel-5.7.38-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415 2704332 Mar 23 2022 mysql-community-libs-5.7.38-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415 1264876 Mar 23 2022 mysql-community-libs-compat-5.7.38-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415 186231736 Mar 23 2022 mysql-community-server-5.7.38-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415 126641600 Mar 23 2022 mysql-community-test-5.7.38-1.el7.x86_64.rpm
3、安装MySQL
[root@localhost ~]# yum -y install mysql-community-*.rpm
4、启动MySQL
[root@localhost ~]# systemctl start mysqld
5、登录MySQL
1)查看初始化后生成的密码
[root@localhost ~]# grep 'password' /var/log/mysqld.log
2022-12-14T08:06:48.018735Z 1 [Note] A temporary password is generated for root@localhost: 9+d?gMK</tEj
2)登录MySQL
[root@localhost ~]# mysql -uroot -p'9+d?gMK</tEj'
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 2
Server version: 5.7.38
Copyright (c) 2000, 2022, Oracle and/or its affiliates.
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.
初始化后需重置密码才能执行sql
mysql> set password=password('Aa123456@!');
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> select version();
+-----------+
| version() |
+-----------+
| 5.7.38 |
+-----------+
1 row in set (0.00 sec)
四、通用二进制安装MySQL
1、下载安装包
[root@localhost ~]# wget https://repo.huaweicloud.com/mysql/Downloads/MySQL-5.7/mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz
2、解压及重命名
[root@localhost ~]# tar xf mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz
[root@localhost ~]# mv mysql-5.7.38-linux-glibc2.12-x86_64 /usr/local/mysql
3、创建MySQL用户
[root@localhost ~]# useradd -s /sbin/nologin mysql
4、初始化MySQL
[root@localhost ~]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/var/lib/mysql --basedir=/usr/local/mysql
5、配置软链接
[root@localhost ~]# ln -sf /usr/local/mysql/bin/mysql* /usr/bin
[root@localhost ~]# ln -sf /var/lib/mysql/mysql.sock /tmp
6、启动MySQL
[root@localhost ~]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@localhost ~]# /etc/init.d/mysqld start
Starting MySQL. SUCCESS!
7、登录MySQL
[root@localhost ~]# grep password /var/log/mysqld.log
2022-12-14T08:37:28.773398Z 1 [Note] A temporary password is generated for root@localhost: mhXYEjmoo4<7
[root@localhost ~]# mysql -uroot -p'mhXYEjmoo4<7'
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 2
Server version: 5.7.38
Copyright (c) 2000, 2022, Oracle and/or its affiliates.
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.
初始化后需重置密码才能执行sql
mysql> set password=password('Aa123456@!');
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> select version();
+-----------+
| version() |
+-----------+
| 5.7.38 |
+-----------+
1 row in set (0.00 sec)
五、源码编译安装MySQL
这里就不写了,请参考博主的另一篇文章:Linux环境源码安装Mysql-5.7.18
继续阅读
MySQL最后更新:2024-1-24