linux安装最新版MySQL详细教程

服务器环境是centos 7.5 这篇教程是通过yum方式安装的。

1.centos下彻底删除MYSQL

1.1 删除Mysql

     yum remove  mysql mysql-server mysql-libs mysql-server;

    find / -name mysql 将找到的相关东西delete掉(rm -rf /var/lib/mysql);

    rpm -qa|grep mysql(查询出来的东东yum remove掉)

    rm /etc/my.cnf

1.2 查看是否还有mysql软件:
      rpm -qa|grep mysql

     如果存在的话,继续删除即可。

     rpm方式安装的mysql

1.3 查看系统中是否以rpm包安装的mysql:

     [root@localhost opt]# rpm -qa | grep -i mysql
     MySQL-server-5.6.17-1.el6.i686
    MySQL-client-5.6.17-1.el6.i686

1.4 卸载mysql

     [root@localhost local]# rpm -e MySQL-server-5.6.17-1.el6.i686
     [root@localhost local]# rpm -e MySQL-client-5.6.17-1.el6.i686

1.5 删除mysql服务

     [root@localhost local]# chkconfig --list | grep -i mysql
     [root@localhost local]# chkconfig --del mysql

1.6 删除分散mysql文件夹

     [root@localhost local]# whereis mysql 或者 find / -name mysql

     mysql: /usr/lib/mysql /usr/share/mysql

     清空相关mysql的所有目录以及文件
    rm -rf /usr/lib/mysql
    rm -rf /usr/share/mysql

    rm -rf /usr/my.cnf

   通过以上几步,mysql应该已经完全卸载干净了.

2.安装依赖

yum install libaio wget -y

3.下载MySQL官网的仓库文件

   MySQL :: Download MySQL Yum Repository

cd /tmp
wget http://repo.mysql.com/mysql80-community-release-el7-3.noarch.rpm
yum localinstall mysql80-community-release-el7-3.noarch.rpm

4.验证仓库是否添加成功

yum repolist enabled | grep "mysql.*-community.*"
[root@VM_0_10_centos tmp]# yum repolist enabled | grep "mysql*"
mysql-connectors-community/x86_64    MySQL Connectors Community              153
mysql-tools-community/x86_64         MySQL Tools Community                   110
mysql80-community/x86_64             MySQL 8.0 Community Server              177

5.安装MySQL

yum install mysql-community-server -y
[root@VM_0_10_centos ~]# yum install mysql-community-server -y
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-server.x86_64 0:8.0.20-1.el7 will be installed
--> Processing Dependency: mysql-community-common(x86-64) = 8.0.20-1.el7 for package: mysql-community-server-8.0.20-1.el7.x86_64
--> Processing Dependency: mysql-community-client(x86-64) >= 8.0.11 for package: mysql-community-server-8.0.20-1.el7.x86_64
--> Running transaction check
---> Package mysql-community-client.x86_64 0:8.0.20-1.el7 will be installed
--> Processing Dependency: mysql-community-libs(x86-64) >= 8.0.11 for package: mysql-community-client-8.0.20-1.el7.x86_64
---> Package mysql-community-common.x86_64 0:8.0.20-1.el7 will be installed
--> Running transaction check
---> Package mysql-community-libs.x86_64 0:8.0.20-1.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

==========================================================================================================
 Package                         Arch            Version                 Repository                  Size
==========================================================================================================
Installing:
 mysql-community-server          x86_64          8.0.20-1.el7            mysql80-community          488 M
Installing for dependencies:
 mysql-community-client          x86_64          8.0.20-1.el7            mysql80-community           47 M
 mysql-community-common          x86_64          8.0.20-1.el7            mysql80-community          609 k
 mysql-community-libs            x86_64          8.0.20-1.el7            mysql80-community          4.5 M

Transaction Summary
==========================================================================================================
Install  1 Package (+3 Dependent packages)

Total size: 540 M
Total download size: 488 M
Installed size: 2.5 G
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
mysql-community-server-8.0.20-1.el7.x86_64.rpm                                     | 488 MB  00:00:17     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : mysql-community-common-8.0.20-1.el7.x86_64                                             1/4 
  Installing : mysql-community-libs-8.0.20-1.el7.x86_64                                               2/4 
  Installing : mysql-community-client-8.0.20-1.el7.x86_64                                             3/4 
  Installing : mysql-community-server-8.0.20-1.el7.x86_64                                             4/4 
  Verifying  : mysql-community-client-8.0.20-1.el7.x86_64                                             1/4 
  Verifying  : mysql-community-libs-8.0.20-1.el7.x86_64                                               2/4 
  Verifying  : mysql-community-common-8.0.20-1.el7.x86_64                                             3/4 
  Verifying  : mysql-community-server-8.0.20-1.el7.x86_64                                             4/4 

Installed:
  mysql-community-server.x86_64 0:8.0.20-1.el7                                                            

Dependency Installed:
  mysql-community-client.x86_64 0:8.0.20-1.el7        mysql-community-common.x86_64 0:8.0.20-1.el7       
  mysql-community-libs.x86_64 0:8.0.20-1.el7         

Complete!
[root@VM_0_10_centos ~]# 

报错:

[root@VM-0-10-centos tmp]# yum install mysql-community-server -y
Last metadata expiration check: 0:03:03 ago on Sun 08 May 2022 03:18:14 PM CST.
All matches were filtered out by modular filtering for argument: mysql-community-server
Error: Unable to find a match: mysql-community-server

解决方法:
先执行:yum module disable mysql
再执行:yum -y install mysql-community-server

6.设置 MySQL8 表名大小写不敏感

在安装完成之后,初始化数据库之前,修改 my.cnf

打开mysql配置文件
vim /etc/my.cnf

在尾部追加一行
lower_case_table_names=1

7.执行

rpm -qi mysql-community-server.x86_64 0:8.0.20-1.el7

8.MySQL 的安装目录

whereis mysql
[root@VM_0_10_centos ~]# whereis mysql
mysql: /usr/bin/mysql /usr/lib64/mysql /usr/share/man/man1/mysql.1.gz

9.启动服务

systemctl start mysqld
systemctl enable mysqld
systemctl status mysqld
[root@VM_0_10_centos ~]# systemctl start mysqld
[root@VM_0_10_centos ~]# systemctl enable mysqld
[root@VM_0_10_centos ~]# systemctl status mysqld
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since Sat 2020-06-20 23:08:31 CST; 32s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
 Main PID: 2546 (mysqld)
   Status: "Server is operational"
   CGroup: /system.slice/mysqld.service
           └─2546 /usr/sbin/mysqld

Jun 20 23:08:20 VM_0_10_centos systemd[1]: Starting MySQL Server...
Jun 20 23:08:31 VM_0_10_centos systemd[1]: Started MySQL Server.

10.查找初始密码

cat /var/log/mysqld.log | grep password
2020-06-20T15:08:25.246427Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: hMg-EjLya3fu

11.进入mysql

mysql -uroot -p
[root@VM_0_10_centos ~]# 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.20

Copyright (c) 2000, 2020, 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> 

12.修改初始密码

ALTER USER 'root'@'localhost' IDENTIFIED BY 'FY200!';
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'FY200!';
Query OK, 0 rows affected (0.01 sec)

13.设置允许远程连接(新版MySQL的方式跟之前的不大一样)

mysql> use mysql;
mysql> select host,user,authentication_string,plugin from user;
mysql> update user set host='%' where user='root';
mysql> flush privileges;
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> select host,user,authentication_string,plugin from user;
+-----------+------------------+------------------------------------------------------------------------+-----------------------+
| host      | user             | authentication_string                                                  | plugin                |
+-----------+------------------+------------------------------------------------------------------------+-----------------------+
| localhost | mysql.infoschema | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password |
| localhost | mysql.session    | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password |
| localhost | mysql.sys        | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password |
| localhost | root             | $A$005$tX!7CaMx;>BS`JyibmXSol9WbbbTnZBXGRpqVIrp5lLbC3Dg5PzkNKk3g5/ | caching_sha2_password |
+-----------+------------------+------------------------------------------------------------------------+-----------------------+
4 rows in set (0.00 sec)

mysql> update user set host='%' where user='root';
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

14.查看字符编码,如果是【utf8mb4】那就不用改了

mysql> status
mysql> status
--------------
mysql  Ver 8.0.20 for Linux on x86_64 (MySQL Community Server - GPL)

Connection id:		8
Current database:	mysql
Current user:		root@localhost
SSL:			Not in use
Current pager:		stdout
Using outfile:		''
Using delimiter:	;
Server version:		8.0.20
Protocol version:	10
Connection:		Localhost via UNIX socket
Server characterset:	utf8mb4
Db     characterset:	utf8mb4
Client characterset:	utf8mb4
Conn.  characterset:	utf8mb4
UNIX socket:		/var/lib/mysql/mysql.sock
Binary data as:		Hexadecimal
Uptime:			16 min 43 sec

Threads: 2  Questions: 46  Slow queries: 0  Opens: 173  Flush tables: 3  Open tables: 91  Queries per second avg: 0.045
--------------

15.接下来就可以通过navicat进行连接了

如果数据库已初始化后要修改表名、字段名大小写敏感配置 ,要先备份数据库,然后删除数据库文件,

[root@VM_0_10_centos ~]# systemctl stop mysqld
[root@VM_0_10_centos ~]# rm -rf /var/lib/mysql
[root@VM_0_10_centos ~]# systemctl start mysqld

再操作步骤6之后的操作。最后再把备份的数据库还原。

  • 4
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值