最近剛接觸linux操作系統,買了個阿里雲服務器,centos7系統,裝mysql數據庫網上查看了別人的博客,方法都不太一樣,自己也試了幾個,結果都沒有成功。
后來搜索發現阿里雲安裝mysql跟有專門的方法,我把雲服務器磁盤初始化之后,重新安裝,然后試了真的安裝成功了,希望這篇博文能幫助以后在阿里雲上安裝mysql的朋友,不用再走我走過的彎路。以下是我測試安裝成功的步驟,命令也可以直接復制粘貼。我看到鏈接地址:https://jingyan.baidu.com/article/454316ab67bd02f7a7c03af4.html
1、
#######安裝rpm包
[root@typecodes ~]# rpm -Uvh http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
2、
這時查看當前可用的mysql安裝資源:
[root@typecodes ~]# yum repolist enabled | grep "mysql.*-community.*"
從上面的列表可以看出,mysql56-community/x86_64和MySQL 5.6 Community Server可以使用。
因此,我們就可以直接用yum方式安裝了MySQL5.6版本了。
[root@typecodes ~]# yum -y install mysql-community-server
3、
#######安裝成功后,將其加入開機啟動
[root@typecodes ~]# systemctl enable mysqld
4、
#######啟動mysql服務進程
[root@typecodes ~]# systemctl start mysqld
5、
#######配置mysql(設置密碼等)
[root@typecodes ~]# mysql_secure_installation
6、
[設置root用戶密碼]
Remove anonymous users? [Y/n] y [刪除匿名用戶]
Disallow root login remotely? [Y/n] y [禁止root遠程登錄]
Remove test database and access to it? [Y/n] y [刪除test數據庫]
Reload privilege tables now? [Y/n] y [刷新權限]
7、
#################設置mysql
登陸:
[root@typecodes ~]# mysql -u root -p
創建用戶:
[root@typecodes ~]# insert into mysql.user(Host,User,Password,ssl_cipher,x509_issuer,x509_subject)values('localhost','baochengwx',password('baochengwx'),'','','');
刷新權限:
[root@typecodes ~]# FLUSH PRIVILEGES;
創建數據庫:
[root@typecodes ~]# create database companys;
分配數據庫給用戶
[root@typecodes ~]# grant all privileges on companys.* to companys identified by 'companys';
修改密碼
UPDATE user SET Password=PASSWORD('newpassword') where USER='root';
遠程登陸
user表中 Host列 'localhost' 改成 '%' (也可以是固定ip、本地登陸localhost、%指不限登陸地址)
最后遠程連接linux雲服務器失敗的話還要在阿里雲上雲服務器管理控制台上,步驟如下:




