打造個人直播間(三)卸載、重裝mysql,創建直播用戶表

00 前言

因爲後臺服務需要用到mysql數據庫,但是因爲之前安裝過,密碼又忘掉了,嘗試了幾種方法,發現都不能跳過密碼登錄,所以乾脆把mysql卸載重裝了。

環境:CentOS 7。

安裝包:mysql 5.7。

01 卸載數據庫

# 卸載mysql服務yum remove -y mysql mysql-server mysql-libs mysql-server;
# 刪除所有mysql相關數據find / -name 'mysql*' | xargs rm -rf;

刪除其餘rpm包

rpm -qa|grep mysql# 查詢出來的rpm使用yum remove掉或者使用rpm -e命令刪除

查出內容如下

[root@hostone lib]# rpm -qa|grep mysqlmysql57-community-release-el7-8.noarchmysql-community-common-5.7.29-1.el7.x86_64

繼續刪除

rpm -e mysql57-community-release-el7-8.noarchrpm -e mysql-community-common-5.7.29-1.el7.x86_64

02 安裝

下載安裝包

# 創建mysql安裝包存放文件夾mkdir -p /usr/local/src/mysql
# 進入目錄cd /usr/local/src/mysql
# 下載5.7 安裝包wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
# 配置安裝依賴yum localinstall -y mysql57-community-release-el7-8.noarch.rpm
# 安裝數據庫yum install -y mysql-community-server
# 數據庫啓動systemctl start mysqld

03 登錄

第一次啓動,從mysqld.log中查看初始化密碼

# 查看初始化密碼grep 'temporary password'  /var/log/mysqld.log

可以看到,查詢密碼如下

[root@hostone mysql]# grep 'temporary password'  /var/log/mysqld.log 2020-02-18T21:46:40.622767Z 1 [Note] A temporary password is generated for root@localhost: p8)<7:geYY;-

使用【mysql -u root -p】命令登錄,密碼爲p8)<7:geYY;-

[root@hostone mysql]# mysql -u root -pEnter password: Welcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 2Server version: 5.7.29
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

登錄成功,修改root密碼

mysql> SET PASSWORD = PASSWORD('Db@369012');Query OK, 0 rows affected, 1 warning (0.00 sec)

可以看到,我的新密碼爲Db@369012。當然,我隨後會把這個密碼改掉。

04 創建數據庫、用戶及數據表

數據庫終於搞定了,接着就要創建我們需要的數據表了。

# 查看數據庫show databases;
# 創建一個新的數據庫livecreate database live;
# 選擇進入剛剛創建的live數據庫use live;
# 查看mysql庫下有哪些數據表,可以看到是空的show tables;
# 創建數據表create table user( id varchar(20), random_name varchar(50));

添加一個非root用戶

# use mysql,創建用戶live,並賦權GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP ON TUTORIALS.* TO 'live'@'%' IDENTIFIED BY 'Live@123';
# 給用戶賦權指定數據庫操作權限grant all privileges on live.* to 'live'@'%';
# 刷新權限FLUSH PRIVILEGES;

報錯遠程機器無法訪問,"Host '183.160.28.242' is not allowed to connect to this MySQL server"。

修改訪問權限

# 進入mysql DBuse mysql
# 修改host爲%update user set host = '%';
# 再次查看select host, user from user;+------+---------------+| host | user |+------+---------------+| % | live || % | mysql.session || % | mysql.sys || % | root |+------+---------------+4 rows in set (0.00 sec)
# 更改host後,發現客戶端還是無法連接,因爲沒有刷新權限FLUSH PRIVILEGES;

刷新權限後可以了。


本文分享自微信公衆號 - 架構師之殤(ysistrue)。
如有侵權,請聯繫 [email protected] 刪除。
本文參與“OSC源創計劃”,歡迎正在閱讀的你也加入,一起分享。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章