Linux服务器使用rpm方式安装MySQL数据库
Linux使用rpm方式安装MySQL数据库主要分为以下几步:
MySQL下载地址:
http://downloads.mysql.com/archives/community/
1、Linux服务器检查是否安装MySQL服务
mysql --version
或
rpm -qa|grep -i mysql
2、下载和安装MySQL源:
wget https://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
yum -y install mysql57-community-release-el7-10.noarch.rpm
3、安装MySQL服务器:yum install mysql-community-server
如果报错:Error: GPG check FAILED
则添加--nogpgcheck参数即可
yum install mysql-community-server --nogpgcheck
4、MySQL安装完成后检查及默认密码修改
查看版本号:mysql --version
查看安装目录:whereis mysql
查看MySQL服务状态:systemctl status mysqld
启动MySQL服务:systemctl start mysqld
查看并修改默认密码:
grep "password" /var/log/mysqld.log
mysql -uroot -p
alter user 'root'@'localhost' IDENTIFIED BY '123456';
5.允许远程连接
use mysql
update user set host='%' where user='root';
flush privileges
6.my.cnf配置修改
#配置最大连接数:
max_connections=1000
#开启binlog日志
server-id=1
log-bin=mysql-bin
log_bin_trust_function_creators=1
具体安装步骤:
下载和安装MySQL源:
[root@iZj6c6to1 servers]# wget https://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
[root@iZj6c6to1 servers]# yum -y install mysql57-community-release-el7-10.noarch.rpm
Last metadata expiration check: 2:27:20 ago on Thu 18 Aug 2022 09:56:28 AM CST.
Dependencies resolved.
============================================================================================================
Package Architecture Version Repository Size
============================================================================================================
Installing:
mysql57-community-release noarch el7-10 @commandline 25 k
Transaction Summary
============================================================================================================
Install 1 Package
Total size: 25 k
Installed size: 30 k
Downloading Packages:
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Installing : mysql57-community-release-el7-10.noarch 1/1
Verifying : mysql57-community-release-el7-10.noarch 1/1
Installed:
mysql57-community-release-el7-10.noarch
Complete!
安装MySQL服务器:
[root@iZj6c6to1 servers]# yum install mysql-community-server
Last metadata expiration check: 0:01:32 ago on Thu 18 Aug 2022 12:23:50 PM CST.
Dependencies resolved.
============================================================================================================
Package Architecture Version Repository Size
============================================================================================================
Installing:
mysql-community-server x86_64 5.7.39-1.el7 mysql57-community 178 M
Installing dependencies:
libaio x86_64 0.3.112-1.2.al8 alinux3-os 33 k
mysql-community-client x86_64 5.7.39-1.el7 mysql57-community 28 M
mysql-community-common x86_64 5.7.39-1.el7 mysql57-community 311 k
mysql-community-libs x86_64 5.7.39-1.el7 mysql57-community 2.6 M
Transaction Summary
============================================================================================================
Install 5 Packages
Total download size: 209 M
Installed size: 892 M
Is this ok [y/N]: y
Downloading Packages:
(1/5): mysql-community-common-5.7.39-1.el7.x86_64.rpm 6.8 MB/s | 311 kB 00:00
(2/5): mysql-community-libs-5.7.39-1.el7.x86_64.rpm 82 MB/s | 2.6 MB 00:00
(3/5): libaio-0.3.112-1.2.al8.x86_64.rpm 205 kB/s | 33 kB 00:00
(4/5): mysql-community-client-5.7.39-1.el7.x86_64.rpm 14 MB/s | 28 MB 00:01
(5/5): mysql-community-server-5.7.39-1.el7.x86_64.rpm 10 MB/s | 178 MB 00:17
------------------------------------------------------------------------------------------------------------
Total 12 MB/s | 209 MB 00:17
warning: /var/cache/dnf/mysql57-community-65b9ecb4cc6a2553/packages/mysql-community-client-5.7.39-1.el7.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID 3a79bd29: NOKEY
MySQL 5.7 Community Server 312 kB/s | 27 kB 00:00
Importing GPG key 0x5072E1F5:
Userid : "MySQL Release Engineering <mysql-build@oss.oracle.com>"
Fingerprint: A4A9 4068 76FC BD3C 4567 70C8 8C71 8D3B 5072 E1F5
From : /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Is this ok [y/N]: y
Key imported successfully
Import of key(s) didn't help, wrong key(s)?
Public key for mysql-community-client-5.7.39-1.el7.x86_64.rpm is not installed. Failing package is: mysql-community-client-5.7.39-1.el7.x86_64
GPG Keys are configured as: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Public key for mysql-community-common-5.7.39-1.el7.x86_64.rpm is not installed. Failing package is: mysql-community-common-5.7.39-1.el7.x86_64
GPG Keys are configured as: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Public key for mysql-community-libs-5.7.39-1.el7.x86_64.rpm is not installed. Failing package is: mysql-community-libs-5.7.39-1.el7.x86_64
GPG Keys are configured as: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Public key for mysql-community-server-5.7.39-1.el7.x86_64.rpm is not installed. Failing package is: mysql-community-server-5.7.39-1.el7.x86_64
GPG Keys are configured as: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
The downloaded packages were saved in cache until the next successful transaction.
You can remove cached packages by executing 'yum clean packages'.
Error: GPG check FAILED
如果报错:Error: GPG check FAILED,则添加--nogpgcheck参数即可
MySQL安装完成后检查及默认密码修改
[root@iZj6c6to1 servers]# mysql --version
mysql Ver 14.14 Distrib 5.7.39, for Linux (x86_64) using EditLine wrapper
[root@iZj6c6to1 servers]#
[root@iZj6c6to1 servers]#
[root@iZj6c6to1 servers]# whereis mysql
mysql: /usr/bin/mysql /usr/lib64/mysql /usr/share/mysql /usr/share/man/man1/mysql.1.gz
[root@iZj6c6to1 servers]#
[root@iZj6c6to1 servers]# systemctl status mysqld
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: enabled)
Active: inactive (dead)
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
[root@iZj6c6to1 servers]#
[root@iZj6c6to1 servers]#
[root@iZj6c6to1 servers]# systemctl start mysqld
[root@iZj6c6to1 servers]# systemctl status mysqld
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2022-08-18 12:31:44 CST; 5s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 44151 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS >
Process: 44102 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 44154 (mysqld)
Tasks: 27 (limit: 12372)
Memory: 299.4M
CGroup: /system.slice/mysqld.service
└─44154 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
Aug 18 12:31:39 iZj6c6to1 systemd[1]: Starting MySQL Server...
Aug 18 12:31:44 iZj6c6to1 systemd[1]: Started MySQL Server.
[root@iZj6c6to1 servers]#
[root@iZj6c6to1 servers]#
[root@iZj6c6to1 servers]#
[root@iZj6c6to1 servers]#
[root@iZj6c6to1 servers]# grep "password" /var/log/mysqld.log
2022-08-18T04:31:40.809033Z 1 [Note] A temporary password is generated for root@localhost: ?h>loMV<Y512
[root@iZj6c6to1 servers]#
[root@iZj6c6to1 servers]#
[root@iZj6c6to1 servers]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.39
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.
mysql>
mysql>
mysql>
mysql>
mysql> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql>
mysql>
mysql> alter user 'root'@'localhost' IDENTIFIED BY '123456';
Query OK, 0 rows affected (0.00 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
mysql>
mysql>
mysql>
[root@iZj6c6to1 ~]#
[root@iZj6c6to1 ~]# ps -ef|grep mysql
mysql 44154 1 0 12:31 ? 00:00:00 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqldmysqld.pid
root 44194 43405 0 12:34 pts/0 00:00:00 mysql -uroot -p
root 44226 44204 0 12:43 pts/1 00:00:00 grep --color=auto mysql
[root@iZj6c6to1 ~]#
MySQL远程连接修改:
[root@iZj6c6to1 ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.39 MySQL Community Server (GPL)
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.
mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql>
mysql> select host from user where user='root';
+-----------+
| host |
+-----------+
| localhost |
+-----------+
1 row in set (0.00 sec)
mysql>
mysql> update user set host='%' where user='root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql>
mysql> select host from user where user='root';
+------+
| host |
+------+
| % |
+------+
1 row in set (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql>
(完)