1. 程式人生 > >ubuntu中mysql的常識

ubuntu中mysql的常識

MySQL安全配置嚮導mysql_secure_installation

 

ubuntu 18.04 上安裝 mysql 5.7 之後,預設沒有設定 root 密碼,印象中之前是有一個引導介面的,現在似乎去掉了。

設定 mysql 初始密碼需要使用命令

sudo mysql_secure_installation

按照提示,一步步操作即可

安裝完mysql-server 會提示可以執行mysql_secure_installation。執行mysql_secure_installation會執行幾個設定:
  a)為root使用者設定密碼
  b)刪除匿名賬號
  c)取消root使用者遠端登入
  d)刪除test庫和對test庫的訪問許可權
  e)重新整理授權表使修改生效

通過這幾項的設定能夠提高mysql庫的安全。建議生產環境中mysql安裝這完成後一定要執行一次mysql_secure_installation,詳細步驟請參看下面的命令.

[[email protected] ~]# mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MySQL to secure it, we'll need the current
password for the root user. If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank, so you should just press enter here. Enter current password for root (enter for none):<–初次執行直接回車 OK, successfully used password, moving on… Setting the root password ensures that nobody can log into the MySQL root user without the proper authorisation. Set root password
? [Y/n] <– 是否設定root使用者密碼,輸入y並回車或直接回車 New password: <– 設定root使用者的密碼 Re-enter new password: <– 再輸入一次你設定的密碼 Password updated successfully! Reloading privilege tables.. … Success! 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? [Y/n] <– 是否刪除匿名使用者,生產環境建議刪除,所以直接回車 … 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? [Y/n] <–是否禁止root遠端登入,根據自己的需求選擇Y/n並回車,建議禁止 … Success! 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? [Y/n] <– 是否刪除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? [Y/n] <– 是否重新載入許可權表,直接回車 … Success! Cleaning up… All done! If you've completed all of the above steps, your MySQL installation should now be secure. Thanks for using MySQL! [[email protected] ~]#
登入mysql資料庫

sudo mysql -u root -p

 

create database 資料庫名稱 default character set utf8mb4 collate utf8mb4_unicode_ci;       ubuntu檔案的鎖:這個是root許可權的一種標誌 linux下資料夾有鎖頭,去掉鎖頭的辦法  去除Ubuntu資料夾有鎖標誌   由於在root許可權下下載的東西,所以在普通使用者下有鎖標誌,雖說在root下什麼都可以操作使用,只要切換到root賬戶操作就ok了,但是看著就很彆扭,如何去除? 1.看到有網友說使用   sudo chmod -R 777     別且說可能有危險,這不廢話麼,對檔案遞迴做改變許可權為可讀可寫可執行,當然沒有鎖了。 但是這就會使得原來的檔案的許可權發生變化。   2.可以把它拷貝到有windows的電腦上……呵呵,這樣當然可以,linux下的許可權什麼的自然全消失。 3.使用命令改變檔案的組使用者   sudo chown 你的使用者名稱 檔名     例如:   sudo chown jack common      事實證明這樣是可以的,但是這樣只是改變common這個資料夾的Group,裡邊的檔案或者資料夾還是有鎖的。所以要   sudo chown jack common/ -R