Linux中安裝MySQL詳細教程

前言

如今紅帽Linux上默認是沒有yum源的mysql

yum軟件倉庫裏面只有MariaDB的安裝包因此咱們須要本身先配置yum源sql


實驗準備(如下操做在VMware中進行)

一臺Linux主機 (我這裏用的是RHEL7.4
已經聯網
不要掛載yum鏡像

數據庫


一、配置yum源

下載yum源(我這裏已經找好了)this

wget 'https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm'

yum源下載連接:MySQLspa

安裝yum源code

rpm -Uvh mysql57-community-release-el7-11.noarch.rpm

查看有哪些版本的mysqlorm

yum repolist all | grep mysql

二、安裝

yum install -y mysql-community-server

三、啓動mysql

注意啓動的時候是mysqld而不是mysqlserver

systemctl start mysqld

查看狀態教程

systemctl status mysqld

四、登陸數據庫,修改數據庫密碼

找到密碼: 紅框的地方就是密碼get

[root@localhost ~]# grep 'temporary password' /var/log/mysqld.log
2020-12-18T15:15:55.572640Z 1 [Note] A temporary password is generated for root@localhost: 9sX3oDXGti)P
密碼:9sX3oDXGti)P

五、登陸MySQL

[root@localhost ~]# mysql -uroot -p'9sX3oDXGti)P'
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.32

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>    ---出現這個表示登陸成功

查看數據庫

mysql>show databases;     ---這裏會報錯,須要從新修改密碼
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

修改密碼

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'XXGC.lab123';  
Query OK, 0 rows affected (0.01 sec)     ---表示修改爲功

刷新

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

退出

mysql> exit

六、使用新密碼登陸數據庫

[root@localhost ~]# mysql -uroot -p'XXGC.lab123'
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 3
Server version: 5.7.32 MySQL Community Server (GPL)

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>     ---登陸成功

查看一下

mysql> show databses;  
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

mysql>

以上就是在RHEL7.4中配置MySQL的教程

相關文章
相關標籤/搜索