阿里云ubuntu mysql_Ubuntu下安装MySQL(阿里云服务器)
安裝客戶端和依賴環(huán)境
sudo apt install mysql-server #安裝mysql服務(wù)器端
sudo apt install mysql-client #安裝mysql客戶端
sudo apt install libmysqlclient-dev #安裝服務(wù)端/客戶端依賴環(huán)境(可有可無,建議安裝)
初始化MySQL(MySQL 5.7并未設(shè)置默認密碼,需要初始化,即運行安全向?qū)?
sudo mysql_secure_installation
安全向?qū)?#xff1a;
1.(是否設(shè)置隨機密碼,Y/y隨機密碼, N/n自己輸入密碼)
VALIDATE PASSWORD PLUGIN can be used to test passwords...
Press y|Y for Yes, any other key for No: N (我的選項)
Please set the password for root here...
New password: (輸入密碼)
Re-enter new password: (重復(fù)輸入)
2.(是否刪除匿名用戶,建議刪除)
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them...
Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y (我的選項)
3.(是否禁止root賬戶遠程登陸,建議禁止)
Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network...
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y (我的選項)
4.(是否刪除test數(shù)據(jù)庫,建議刪除)
By default, MySQL comes with a database named 'test' that
anyone can access...
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Y (我的選項)
5.(是否重新加載權(quán)限表,應(yīng)該重新加載)
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y (我的選項)
修改配置文件(具體的看是否需要遠程訪問數(shù)據(jù)庫)
sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
/bind #查找bind-address,然后注釋該行并保存
重啟MySQL服務(wù)
sudo service mysql restart
從MySQL-Client登陸MySQL(首次登陸建議以root用戶身份登陸)
mysql -u root -p
創(chuàng)建用來遠程登陸的用戶
create user 用戶名(非root用戶)
為新建立的用戶賦予相應(yīng)權(quán)限
grant all privileges on *.* to 'username'@'%' identified by 'password' with grant option;
# grant 修改用戶權(quán)限的關(guān)鍵字
# all(增、刪、改、查、創(chuàng)建數(shù)據(jù)庫和表等,除grant外的所有權(quán)限)
# on 后面跟數(shù)據(jù)庫名.表名(*代表所有)
# to 'username'@'ip'(%代表所有IP均可訪問該數(shù)據(jù)庫)
# identified by 'password'
# 關(guān)鍵字:privileges、with grant option
必須使用flush privileges的兩種情況
1、改密碼。
2、授權(quán)超用戶。
flush privileges 命令本質(zhì)上的作用是將當前user和privilige表中的用戶信息/權(quán)限設(shè)置從mysql庫(MySQL數(shù)據(jù)庫的內(nèi)置庫)中提取到內(nèi)存里
總結(jié)
以上是生活随笔為你收集整理的阿里云ubuntu mysql_Ubuntu下安装MySQL(阿里云服务器)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: [云炬创业学笔记]第三章商业创意的发掘与
- 下一篇: php怎么获得产品id,php – 如