阿里云(CentOS7.4)安裝MySQL,以及本地遠程連接MySQL
阿里云yum安裝MySQL
第一步:檢查是否本機存在mysql
rpm -qa | grep mysql
yum info mysql-community-server
第二步:拷貝mysql官網yum-community-mysql的下載地址
https://dev.mysql.com/downloads/

https://dev.mysql.com/downloads/file/?id=484922

第三步:安裝mysql-community-server
rpm -Uvh https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
第四步:再次檢查mysql-community-server資訊
yum info install mysql-community-server
Loaded plugins: fastestmirror
mysql-connectors-community | 2.6 kB 00:00:00
mysql-tools-community | 2.6 kB 00:00:00
mysql80-community | 2.6 kB 00:00:00
(1/3): mysql-connectors-community/x86_64/primary_db | 68 kB 00:00:00
(2/3): mysql-tools-community/x86_64/primary_db | 83 kB 00:00:00
(3/3): mysql80-community/x86_64/primary_db | 128 kB 00:00:00
Loading mirror speeds from cached hostfile
Available Packages
Name : mysql-community-server
Arch : x86_64
Version : 8.0.22
Release : 1.el7
Size : 510 M
Repo : mysql80-community/x86_64
Summary : A very fast and reliable SQL database server
URL : http://www.mysql.com/
License : Copyright (c) 2000, 2020, Oracle and/or its affiliates. Under GPLv2 license as shown in the Description field.
Description : The MySQL(TM) software delivers a very fast, multi-threaded, multi-user,
: and robust SQL (Structured Query Language) database server. MySQL Server
: is intended for mission-critical, heavy-load production systems as well
: as for embedding into mass-deployed software. MySQL is a trademark of
: Oracle and/or its affiliates
:
: The MySQL software has Dual Licensing, which means you can use the MySQL
: software free of charge under the GNU General Public License
: (http://www.gnu.org/licenses/). You can also purchase commercial MySQL
: licenses from Oracle and/or its affiliates if you do not wish to be bound by the terms of
: the GPL. See the chapter "Licensing and Support" in the manual for
: further info.
:
: The MySQL web site (http://www.mysql.com/) provides the latest news and
: information about the MySQL software. Also please see the documentation
: and the manual for more information.
:
: This package includes the MySQL server binary as well as related utilities
: to run and administer a MySQL server.
第五步:安裝MySQL:我們安裝的是MySQL8.0.22版本
yum -y install mysql-community-server
第六步:檢查MySQL的狀態,并啟動MySQL(這里是CentOS7.4的指令)
//檢查MySQL的狀態
systemctl status mysqld
//啟動MySQL
systemctl start mysqld
第七步:我們查看此時的臨時密碼,并進行重置root密碼操作
//查看root賬戶的臨時密碼
grep "temporary password" /var/log/mysqld.log
//進行root密碼的重置操作
//注意:MySQL8版本以上的密碼初始安全級別為中等:密碼需要設定為至少8位,包括大寫字母和特殊字符
mysqladmin -u root -p password
先輸入上面的臨時密碼,再輸入你設定的新密碼,同時進行密碼的確認
第八步:此時你就可以使用你的root賬戶和密碼進行MySQL的登錄操作了
mysql -u root -p
輸入密碼: 你的密碼
登錄成功!!!
遠程連接阿里云的MySQL資料庫
1、賦予賬號遠程登錄權限
MySQL默認情況下只允許用戶本地登錄,所有需要賦予用戶遠程登錄的權限,進去MySQL,
mysql> grant all privileges on *.* to '用戶'@'ip' identified by '密碼' with grant option;
mysql> flush privileges;
第一句陳述句陳述句中,*.*代表所有庫表,若想給予所有IP權限,"ip"寫成“%”,所以第一句sql的意思是給予來自所有IP地址的通過“用戶”,
“密碼”登錄的用戶對所有庫表的所有操作權限,
第二句sql,重繪權限,
然后同樣重啟MySQL生效 systemctl restart mysql
注意:MySQL8版本以上不支持上面的寫法,需要按照下面命令執行:
CREATE USER 'root'@'%' IDENTIFIED BY '你的密碼';
GRANT ALL ON *.* TO 'root'@'%';
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '你的密碼';
三條命令按順序執行完成后,重繪權限:
flush privileges
最后重啟MySQL生效
2、檢查防火墻
服務器是否開啟了防火墻,防火墻是否允許3306埠連接
登錄云服務器控制臺->安全組->配置規則,默認情況下,入方向阿里云只允許訪問3389,22,-1埠,所以添加3306,即可成功

登錄MySQL出現如下錯誤解決方法
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password)
這個問題一般是重置密碼出現的問題,所以我們需要按照以下步驟進行密碼的重新設定操作
第一步:找到my.cnf檔案的位置,我這里的my.cnf檔案在/etc目錄下
在[mysqld]下方添加下面代碼
//直接跳過密碼進行登錄
skip-grant-tables
第二步:我們直接登錄MySQL,此時無需密碼可以登錄成功
//1.登錄MySQL
mysql -u root
//2.重置修改root賬戶的密碼
mysql>alter user 'root'@'localhost' identitfied by '你要設定的密碼';
如果出現1290ERROR,使用 flush privileges命令重繪一下權限再執行上面操作即可
//3.最后再進行重繪權限操作
mysql>flush privileges
mysql>quit
//4.將 /etc/my.cnf中的skip-grant-tables進行洗掉操作
//5.重啟mysql
systemctl restart mysqld
此時再使用你的root賬戶和新重置的密碼進行登錄則直接完美登錄!
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/220889.html
標籤:python
上一篇:在freemarker模板中遍歷資料模型List<JavaBean>報空指標例外
下一篇:MySQL練習
