我在Linux上部署MySQL的过程记录
(做个笔记,自己以后忘了方便查找,会持续更新…)
一、删除Linux原始自带的MariaDB
因为MariaDB是和MySQL同类型的数据库工具,二者只能选一,CentOS7默认安装了MariaDB
因此,需要先删除MariaDB
先检查一下已安装的MariaDB列表
rpm -qa | grep mariadb
[root@localhost mysql]# rpm -qa | grep mariadb
mariadb-5.5.68-1.el7.x86_64
mariadb-libs-5.5.68-1.el7.x86_64
使用命令删除
rpm -e --nodeps mariadb-5.5.68-1.el7.x86_64
rpm -e --nodeps mariadb-libs-5.5.68-1.el7.x86_64
删完后再检查一遍
[root@localhost mysql]# rpm -qa | grep mariadb
[root@localhost mysql]#
二、下载安装MySQL
1.下载MySQL的repo源
wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
[root@localhost mysql]# wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
--2022-06-20 01:24:26-- http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
Resolving repo.mysql.com (repo.mysql.com)... 23.194.211.12
Connecting to repo.mysql.com (repo.mysql.com)|23.194.211.12|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 6140 (6.0K) [application/x-redhat-package-manager]
Saving to: ‘mysql-community-release-el7-5.noarch.rpm’
100%[===========================================================================================================================================================>] 6,140 --.-K/s in 0s
2022-06-20 01:24:27 (527 MB/s) - ‘mysql-community-release-el7-5.noarch.rpm’ saved [6140/6140]
2.下载完成后开始安装repo源
sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm
[root@localhost mysql]# sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-release-el7-5 ################################# [100%]
3.开始安装MySQL
yum install mysql-server
[root@localhost mysql]# sudo yum install mysql-server
Loaded plugins: fastestmirror, langpacks
Existing lock /var/run/yum.pid: another copy is running as pid 63770.
Another app is currently holding the yum lock; waiting for it to exit...
..................................太长省略...........................................
Installed:
mysql-community-server.x86_64 0:5.6.51-2.el7
Dependency Installed:
mysql-community-client.x86_64 0:5.6.51-2.el7 mysql-community-common.x86_64 0:5.6.51-2.el7 mysql-community-libs.x86_64 0:5.6.51-2.el7 perl-Compress-Raw-Bzip2.x86_64 0:2.061-3.el7
perl-Compress-Raw-Zlib.x86_64 1:2.061-4.el7 perl-DBI.x86_64 0:1.627-4.el7 perl-Data-Dumper.x86_64 0:2.145-3.el7 perl-IO-Compress.noarch 0:2.061-2.el7
perl-Net-Daemon.noarch 0:0.48-5.el7 perl-PlRPC.noarch 0:0.2020-14.el7
Complete!
三、启动MySQL
sudo service mysqld start
[root@localhost mysql]# sudo service mysqld start
Starting mysqld: [ OK ]
四、异常报错处理
错误一:
-bash: wget: 未找到命令
问题原因:显而易见,未安装wget
解决方案:安装wget
yum -y install wget
错误二:
[root@localhost ~]# sudo service mysqld start
Redirecting to /bin/systemctl start mysqld.service
问题原因:MySQL启动失败
解决方案:使用systemctl 重新启动
systemctl restart mysqld.service
[root@localhost ~]# systemctl restart mysqld.service
[root@localhost ~]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.51 MySQL Community Server (GPL)
Copyright (c) 2000, 2021, 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 |
+--------------------+
3 rows in set (0.01 sec)
mysql>