MySQL在Centos7环境安装
阿里云国内75折 回扣 微信号:monov8 |
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6 |
目录
说明
- 安装与卸载中⽤⼾全部切换成为root⼀旦安装普通⽤⼾能使⽤的
- 初期练习mysql不进⾏⽤⼾管理全部使⽤root进⾏适应mysql语句后⾯博客有⽤⼾管理可以考虑新建普通⽤⼾
1. 卸载不要的环境
[sz@VM-0-3-centos ~]$ ps ajx |grep mariadb
13134 14844 14843 13134 pts/0 14843 S+ 1005 0:00 grep --color=auto
mariadb
19010 19187 19010 19010 ? -1 Sl 27 16:55 /usr/libexec/mysqld --
basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --
log-error=/var/log/mariadb/mariadb.log --pid-file=/var/run/mariadb/mariadb.pid
--socket=/var/lib/mysql/mysql.sock
[sz@VM-0-3-centos ~]$ systemctl stop mariadb.service
==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units ===
Authentication is required to manage system services or units.
Authenticating as: root
Password:
==== AUTHENTICATION COMPLETE ===
[sz@VM-0-3-centos ~]$ ps axj |grep mariadb
13134 14976 14975 13134 pts/0 14975 S+ 1005 0:00 grep --color=auto
mariadb
2.检查系统安装包
[sz@VM-0-3-centos ~]$ rpm -qa | grep mariadb
or
[sz@VM-0-3-centos ~]$ rpm -qa | grep mysql
...
...
...
[root@bite-alicloud mysql]
mysql-community-common-5.7.41-1.el7.x86_64
mysql-community-server-5.7.41-1.el7.x86_64
mysql57-community-release-el7-11.noarch
mysql-community-client-5.7.41-1.el7.x86_64
mysql-community-libs-5.7.41-1.el7.x86_64
3.卸载这些默认安装包
[sz@VM-0-3-centos ~]$ sudo yum remove mariadb
备份/etc/my.cnf,备份/var/lib/mysql数据
4.获取mysql官⽅yum源
5. 安装mysql yum源对⽐前后yum源
[sz@VM-0-3-centos 9.9]$ ls
mysql57-community-release-el7-10.noarch.rpm
查看你本地的yum源 [我的和你的肯定不同但是没有mysql相关的yum源]
[sz@VM-0-3-centos 9.9]$ ls /etc/yum.repos.d/ -al
total 88
drwxr-xr-x. 2 root root 4096 Apr 9 15:43 .
drwxr-xr-x. 106 root root 12288 Apr 12 10:50 ..
-rw-r--r-- 1 root root 2523 Dec 26 19:31 Centos-Base.repo
-rw-r--r-- 1 root root 614 Nov 10 18:42 CentOS-Base.repo_bak
-rw-r--r-- 1 root root 2523 Jun 16 2018 CentOS-Base.repo.bak
-rw-r--r-- 1 root root 1309 Apr 8 2020 CentOS-CR.repo
-rw-r--r-- 1 root root 649 Apr 8 2020 CentOS-Debuginfo.repo
-rw-r--r-- 1 root root 230 Nov 10 18:42 CentOS-Epel.repo
-rw-r--r-- 1 root root 314 Apr 8 2020 CentOS-fasttrack.repo
-rw-r--r-- 1 root root 630 Apr 8 2020 CentOS-Media.repo
-rw-r--r-- 1 root root 998 Dec 11 2018 CentOS-SCLo-scl.repo
-rw-r--r-- 1 root root 971 Oct 29 2018 CentOS-SCLo-scl-rh.repo
-rw-r--r-- 1 root root 1331 Apr 8 2020 CentOS-Sources.repo
-rw-r--r-- 1 root root 7577 Apr 8 2020 CentOS-Vault.repo
-rw-r--r-- 1 root root 616 Apr 8 2020 CentOS-x86_64-kernel.repo
-rw-r--r-- 1 root root 1919 Apr 8 23:57 docker-ce.repo
-rw-r--r-- 1 root root 1050 Nov 1 04:33 epel.repo
-rw-r--r-- 1 root root 1149 Nov 1 04:33 epel-testing.repo
-rw-r--r-- 1 root root 173 Dec 9 16:08 google-chrome.repo
[sz@VM-0-3-centos 9.9]$ rpm -Uvh mysql57-community-release-el7-10.noarch.rpm
warning: mysql57-community-release-el7-10.noarch.rpm: Header V3 DSA/SHA1
Signature, key ID 5072e1f5: NOKEY
error: can't create transaction lock on /var/lib/rpm/.rpm.lock (Permission
denied)
[sz@VM-0-3-centos 9.9]$ sudo rpm -Uvh mysql57-community-release-el7-
10.noarch.rpm
[sudo] password for whb:
warning: mysql57-community-release-el7-10.noarch.rpm: Header V3 DSA/SHA1
Signature, key ID 5072e1f5: NOKEY
Preparing...
Updating / installing...
1:mysql57-community-release-el7-10
[sz@VM-0-3-centos 9.9]$ ls /etc/yum.repos.d/ -al
total 96
drwxr-xr-x. 2 root root 4096 Apr 12 11:04 .
drwxr-xr-x. 106 root root 12288 Apr 12 10:50 ..
-rw-r--r-- 1 root root 2523 Dec 26 19:31 Centos-Base.repo
-rw-r--r-- 1 root root 614 Nov 10 18:42 CentOS-Base.repo_bak
-rw-r--r-- 1 root root 2523 Jun 16 2018 CentOS-Base.repo.bak
-rw-r--r-- 1 root root 1309 Apr 8 2020 CentOS-CR.repo
-rw-r--r-- 1 root root 649 Apr 8 2020 CentOS-Debuginfo.repo
-rw-r--r-- 1 root root 230 Nov 10 18:42 CentOS-Epel.repo
-rw-r--r-- 1 root root 314 Apr 8 2020 CentOS-fasttrack.repo
-rw-r--r-- 1 root root 630 Apr 8 2020 CentOS-Media.repo
-rw-r--r-- 1 root root 998 Dec 11 2018 CentOS-SCLo-scl.repo
-rw-r--r-- 1 root root 971 Oct 29 2018 CentOS-SCLo-scl-rh.repo
-rw-r--r-- 1 root root 1331 Apr 8 2020 CentOS-Sources.repo
-rw-r--r-- 1 root root 7577 Apr 8 2020 CentOS-Vault.repo
-rw-r--r-- 1 root root 616 Apr 8 2020 CentOS-x86_64-kernel.repo
-rw-r--r-- 1 root root 1919 Apr 8 23:57 docker-ce.repo
-rw-r--r-- 1 root root 1050 Nov 1 04:33 epel.repo
-rw-r--r-- 1 root root 1149 Nov 1 04:33 epel-testing.repo
-rw-r--r-- 1 root root 173 Dec 9 16:08 google-chrome.repo
-rw-r--r-- 1 root root 1627 Apr 5 2017 mysql-community.repo
-rw-r--r-- 1 root root 1663 Apr 5 2017 mysql-community-source.repo
6. 看看能不能正常⼯作
[sz@VM-0-3-centos 9.9]$ yum list |grep mysql
Repository epel is listed more than once in the configuration
mysql57-community-release.noarch el7-10 installed
akonadi-mysql.x86_64 1.9.2-4.el7 base
anope-mysql.x86_64 2.0.9-3.el7 epel
apr-util-mysql.x86_64 1.5.2-6.el7 base
calligra-kexi-driver-mysql.x86_64 2.9.10-2.el7 epel
collectd-mysql.x86_64 5.8.1-1.el7 epel
dmlite-plugins-mysql.x86_64 1.14.2-1.el7 epel
dovecot-mysql.x86_64 1:2.2.36-8.el7 base
7. 安装mysql服务
[sz@VM-0-3-centos 9.9]$ sudo yum install -y mysql-community-server
[sudo] password for whb:
Loaded plugins: aliases, auto-update-debuginfo, fastestmirror, protectbase
Repository epel is listed more than once in the configuration
...
Installing : mysql-community-common-5.7.33-1.el7.x86_64
Installing : mysql-community-libs-5.7.33-1.el7.x86_64
Installing : mysql-community-client-5.7.33-1.el7.x86_64
Installing : mysql-community-server-5.7.33-1.el7.x86_64
...
8. 查看配置⽂件和数据存储位置
[sz@VM-0-3-centos 9.9]$ ls /etc/my.cnf
/etc/my.cnf
[sz@VM-0-3-centos 9.9]$ sudo ls /var/lib/mysql
.....
9. 启动服务
[sz@VM-0-3-centos 9.9]$ systemctl start mysqld.service
==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units ===
Authentication is required to manage system services or units.
Authenticating as: root
Password:
==== AUTHENTICATION COMPLETE ===
10. 查看启动服务
[sz@VM-0-3-centos 9.9]$ ps axj |grep mysqld
1 23183 23182 23182 ? -1 Sl 27 0:00 /usr/sbin/mysqld --
daemonize --pid-file=/var/run/mysqld/mysqld.pid
13134 23243 23242 13134 pts/0 23242 S+ 1005 0:00 grep --color=auto mysqld
11. 登陆⽅法⼀
[sz@VM-0-3-centos 9.9]$ sudo grep 'temporary password' /var/log/mysqld.log
2021-04-12T03:23:46.153263Z 1 [Note] A temporary password is generated for
root@localhost: yLMalT:v+5l*
[sz@VM-0-3-centos 9.9]$ mysql -uroot -p
Enter password:
mysql> set global validate_password_policy=0;
Query OK, 0 rows affected (0.00 sec)
mysql> set global validate_password_length=1;
Query OK, 0 rows affected (0.00 sec)
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'qwer@wu.888';
Query OK, 0 rows affected (0.00 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
12. 登陆⽅法二
13. 登陆⽅法三
[root@bite-alicloud mysql]
在[mysqld]最后⼀栏配置(不知道是什么就放在配置⽂件最后) 加⼊: skip-grant-tables 选项,
并保存退出
[root@bite-alicloud mysql]
[root@bite-alicloud mysql]
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.41 MySQL Community Server (GPL)
Copyright (c) 2000, 2023, 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>
14. 设置开机启动[可以不设]
systemctl enable mysqld
systemctl daemon-reload
15. 配置my.cnf
[sz@VM-0-3-centos 9.9]$ cat /etc/my.cnf
[mysql]
[mysqld]
Remove leading
Remove leading
Remove leading
port=3306
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
symbolic-links=0
og-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
character-set-server=utf8
default-storage-engine=innodb
16. 常见问题
mysql 已经配置了客⼾端服务器utf8编码但是⽆法输⼊中⽂
确保您在终端命令⾏中可以输⼊中⽂
[whb@VM-0-3-centos ~]$ env |grep LANG
LANG=en_US.utf8
安装遇到秘钥过期的问题
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
解决⽅案
rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
阿里云国内75折 回扣 微信号:monov8 |
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6 |