mysql 安裝:mysql
1.切換root權限: 輸入 sudo su 回車,輸入root賬號密碼 2.安裝MySql 說明:默認狀況下,只有最新版本的MySql包含在APT軟件包存儲庫中,安裝最新版本的MySql只需更新服務器上的包索引,並安裝默認的包 apt-get。 apt-get update apt-get install mysql-server 1 2 安裝過程當中會彈出建立超級管理員的用戶名和密碼提示,選擇你本身經常使用的且容易記住的用戶名密碼即刻 3.配置MySql 由於是全新安裝,您須要運行附帶的安全腳本。這會更改一些不太安全的默認選項,例如遠程 root 登陸和示例用戶。在舊版本的 MySQL 上,您須要手動初始化數據目錄,但 Mysql 5.7 已經自動完成了。 運行安全腳本。 sudo mysql_secure_installation 1 以後會有一下提示,選擇本身合適的 root@localhost:/# sudo mysql_secure_installation (修改root密碼) Securing the MySQL server deployment. Enter password for user root: 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: y(是否安裝密碼安全插件,開發環境能夠選n) There are three levels of password validation policy: LOW Length >= 8 MEDIUM Length >= 8, numeric, mixed case, and special characters STRONG Length >= 8, numeric, mixed case, special characters and dictionary file Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: (安全模式0低,1中等,2強) Invalid option provided. There are three levels of password validation policy: LOW Length >= 8 MEDIUM Length >= 8, numeric, mixed case, and special characters STRONG Length >= 8, numeric, mixed case, special characters and dictionary file Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 2 Using existing password for root. Estimated strength of the password: 25 Change the password for root ? ((Press y|Y for Yes, any other key for No) : n … skipping. 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) : n(是否刪除匿名用戶) … skipping. 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) : n(是否刪除測試數據庫) … skipping. 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數據庫安裝完成! 4.檢測MySql服務 查看進程:ps -ef|grep mysql 啓動服務:service mysql start 中止服務:service mysql stop 重啓服務:service mysql restart 5.設置MySQL遠程訪問權限 sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf (編輯此配置文件) #bind-address = 127.0.0.1 (註釋本地IP) bind-address = 0.0.0.0 (或者 從新 添加一行) 退出編輯模式保存文件 進入MySql 命令行 mysql -u root -p 回車,輸入密碼 受權root用戶訪問權限,並刷新權限,此處的root可用其它MySQL用戶替換,pwd部分需替換爲該用戶對應的密碼 grant all privileges on *.* to root@"%" identified by "pwd" with grant option;(分配權限) flush privileges;(刷新權限) exit;(退出) 重啓MySql服務 service mysql restart 6.查詢防火牆狀態 sudo ufw status 關閉防火牆 sudo ufw disable 開啓 防火牆 sudo ufw enable 7.卸載MySql數據庫 sudo apt purge mysql-* sudo rm -rf /etc/mysql/ /var/lib/mysql sudo apt autoremove sudo apt autoclean --------------------- 做者:u014716732 來源:CSDN 原文:https://blog.csdn.net/u014716732/article/details/79056158 版權聲明:本文爲博主原創文章,轉載請附上博文連接!