日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

ubuntu server mysql_Ubuntu18.04 Server搭建MySQL服务器

發布時間:2024/1/18 数据库 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ubuntu server mysql_Ubuntu18.04 Server搭建MySQL服务器 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

安裝Ubuntu系統就不在這里贅述了,之前文章里寫過,哈哈。話不多說,趕緊開始

一、安裝MySQL數據庫

檢查一下有沒有安裝過MySQL,如果沒有安裝就沒有內容,放心安裝好了

dpkg -l | mysql-server

安裝MySQL命令, -y的意思就是在安裝過程中遇到是否繼續的提示就不用手動在敲y了,當然也可以不加y,看你心情了

sudo apt install mysql-server -y

在安裝過程中,我遇到了一個問題,報錯信息如下:

百度了n中方法也沒有解決,其中最多的是這種方法,將info文件中的內容清空,然后在重新更新,類似于這種(但是我試了,還是不行):

于是,我就更新了軟件包和列表,用下邊兩個命令,第一個命令時間可能有一點長。

sudo apt-getupgrade # 更新所有的軟件包

sudo apt update # 更新軟件包列表

然后再次安裝MySQL就沒問題了。安裝好之后,用命令來檢查,通過上述命令檢查之后,如果看到有 mysql 的socket處于 LISTEN 狀態則表示安裝成功

netstat -tap | grep mysql

到這一步,安裝就完成了,接下來開始配置數據庫。

二、配置數據庫

為了確保數據庫的安全性和正常運轉,對數據庫進行初始化操作。這個初始化操作涉及下面5個步驟。

(1)安裝驗證密碼插件。

(2)設置root管理員在數據庫中的專有密碼。

(3)隨后刪除匿名賬戶,并使用root管理員從遠程登錄數據庫,以確保數據庫上運行的業務的安全性。

(4)刪除默認的測試數據庫,取消測試數據庫的一系列訪問權限。

(5)刷新授權列表,讓初始化的設定立即生效。

對于上述數據庫初始化的操作步驟,在下面的輸出信息旁邊我做了簡單注釋。

root@ubuntu-virtual-machine:~# mysql_secure_installation

Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

VALIDATE PASSWORD PLUGIN can be used to test passwords

and improve security. It checks the strength of password

and allows the users to set only those passwords which are

secure enough. Would you like to setup VALIDATE PASSWORD plugin?? ??#?要安裝驗證密碼插件嗎?

Press y|Y for Yes, any other key for No: N? ?# 這里我選擇N

Please set the password for root here.

New password:? ?#?輸入要為root管理員設置的數據庫密碼

Re-enter new password:? ?#?再次輸入密碼

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. This is intended only for

testing, and to make the installation go a bit smoother.

You should remove them before moving into a production

environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : y? ??#?刪除匿名賬戶

Success.

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) : N? ?#?禁止root管理員從遠程登錄,這里我沒有禁止

... skipping.

By default, MySQL comes with a database named 'test' that

anyone can access. This is also intended only for testing,

and should be removed before moving into a production

environment.

Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y??#?刪除test數據庫并取消對它的訪問權限

- Dropping test database...

Success.

- Removing privileges on test database...

Success.

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???#?刷新授權表,讓初始化后的設定立即生效

Success.

All done!

檢查MySQL服務狀態:

systemctl status mysql

顯示如下結果說明mysql服務運行是正常的:

用mysql -u root -p命令,Enter password:處輸入剛設置的密碼,回車,就能夠進入mysql數據庫。

使用 use mysql; 命令打開mysql命名的數據庫,顯示當前數據庫的表:show tables; 查詢user表里的數據:select * from user;(user表里是mysql數據庫的所有賬戶信息)

我這是新搭建的數據庫,所以什么都沒有,哈哈!!

現在配置mysql允許遠程訪問,首先編輯 /etc/mysql/mysql.conf.d/mysqld.cnf 配置文件:

vim /etc/mysql/mysql.conf.d/mysqld.cnf

注釋掉bind-address? ? ? ? ? = 127.0.0.1

保存退出,然后進入mysql數據庫,執行授權命令:

mysql -u root -p

mysql> grant all on *.* to root@'%' identified by '你的密碼'with grant option;

mysql>flush privileges; # 刷新權限

mysql> exit

然后執行exit命令退出mysql服務,再執行如下命令重啟mysql:

systemctl restart mysql

主機名或IP填寫Ubuntu的IP地址,連接成功。

三、創建新的數據庫用戶

由于在工作中不會用到root用戶,所以創建了一個新的用戶。

首先是先登錄數據庫

# 登錄數據庫

sudo mysql-u root -p

# 查看所有用戶

SELECT User,Host FROM mysql.user;

創建新的數據庫用戶

mysql> CREATE USER 'dvtdev'@'%' IDENTIFIED BY '123456';

給用戶授權

mysql> GRANT ALL PRIVILEGES ON *.* TO 'dvtdev'@'%' WITH GRANT OPTION;

mysql>flush privileges; # 刷新權限

mysql> exit

別忘了重啟服務:systemctl restart mysql

總結

以上是生活随笔為你收集整理的ubuntu server mysql_Ubuntu18.04 Server搭建MySQL服务器的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。