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

歡迎訪問 生活随笔!

生活随笔

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

数据库

【数据库】Ubuntu18.04安装MySQL详解

發布時間:2024/4/24 数据库 43 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【数据库】Ubuntu18.04安装MySQL详解 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

00. 目錄

文章目錄

    • 00. 目錄
    • 01. 安裝MySQL
    • 02. 配置MySQL
    • 03. 查看MySQL狀態
    • 04. 配置遠程訪問MySQL
    • 05. 問題分析
    • 06. 附錄

01. 安裝MySQL

1.1 更新軟件源

deng@itcast:~$ sudo apt update

1.2 安裝mysql-server

deng@itcast:~$ sudo apt install mysql-server 正在讀取軟件包列表... 完成 正在分析軟件包的依賴關系樹 正在讀取狀態信息... 完成 下列軟件包是自動安裝的并且現在不需要了:libnginx-mod-http-geoip libnginx-mod-http-image-filterlibnginx-mod-http-xslt-filter libnginx-mod-mail libnginx-mod-stream nginx-commonnginx-core 使用'sudo apt autoremove'來卸載它(它們)。 將會同時安裝下列軟件:libaio1 libevent-core-2.1-6 libhtml-template-perl mysql-client-5.7mysql-client-core-5.7 mysql-common mysql-server-5.7 mysql-server-core-5.7 建議安裝:libipc-sharedcache-perl mailx tinyca 下列【新】軟件包將被安裝:libaio1 libevent-core-2.1-6 libhtml-template-perl mysql-client-5.7mysql-client-core-5.7 mysql-common mysql-server mysql-server-5.7mysql-server-core-5.7 升級了 0 個軟件包,新安裝了 9 個軟件包,要卸載 0 個軟件包,有 635 個軟件包未被升級。 需要下載 19.1 MB 的歸檔。 解壓縮后會消耗 155 MB 的額外空間。 您希望繼續執行嗎? [Y/n]

1.3 安裝libmysqlclient-dev

deng@itcast:~$ sudo apt install libmysqlclient-dev 正在讀取軟件包列表... 完成 正在分析軟件包的依賴關系樹 正在讀取狀態信息... 完成 下列軟件包是自動安裝的并且現在不需要了:libnginx-mod-http-geoip libnginx-mod-http-image-filterlibnginx-mod-http-xslt-filter libnginx-mod-mail libnginx-mod-stream nginx-commonnginx-core 使用'sudo apt autoremove'來卸載它(它們)。 將會同時安裝下列軟件:libmysqlclient20 libssl-dev libssl1.1 zlib1g-dev 建議安裝:libssl-doc

02. 配置MySQL

執行如下命令

deng@itcast:~$ sudo 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? #1. 選擇N Press y|Y for Yes, any other key for No: N#2. 設置密碼 Please set the password for root here.New password: Re-enter new password: #3. 是否移除用戶 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.#4. 不允許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 Success. #5. 是否移除test數據庫 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.#6. 重新加載表 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! deng@itcast:~$

03. 查看MySQL狀態

顯示active表示已經在運行

deng@itcast:~$ systemctl status mysql.service ● mysql.service - MySQL Community ServerLoaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabledActive: active (running) since Sat 2020-02-29 22:00:07 CST; 9min agoMain PID: 6032 (mysqld)Tasks: 29 (limit: 2292)CGroup: /system.slice/mysql.service└─6032 /usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/mysqld.pid2月 29 22:00:07 itcast systemd[1]: Starting MySQL Community Server... 2月 29 22:00:07 itcast systemd[1]: Started MySQL Community Server.

04. 配置遠程訪問MySQL

在Ubuntu下MySQL缺省是只允許本地訪問的,如果需要第三方工具連接MySQL則需要進行配置。

4.1 登錄MySQL數據庫

deng@itcast:~$ sudo mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 6 Server version: 5.7.29-0ubuntu0.18.04.1 (Ubuntu)Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql>

4.2 授權(具有所有數據庫所有的權限)

mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION; Query OK, 0 rows affected, 1 warning (0.00 sec)mysql>

4.3 刷新權限

mysql> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.00 sec)mysql>

05. 問題分析

問題1

ERROR 2003 (HY000): Can't connect to MySQL server on '192.168.13.143' (111)

解決辦法:

將mysql配置文件中的bind-address = 127.0.0.1注釋掉

deng@itcast:~$ sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf 41 # Instead of skip-networking the default is now to listen only on42 # localhost which is more compatible and is not less secure.43 #bind-address = 127.0.0.1

問題2

ERROR 1045 (28000): Access denied for user 'root'@'192.168.13.143' (using password: YES)

解決辦法

在[mysqld]后面任意一行添加“skip-grant-tables”用來跳過密碼驗證的過程

[mysqld] # # * Basic Settings # user = mysql pid-file = /var/run/mysqld/mysqld.pid socket = /var/run/mysqld/mysqld.sock port = 3306 basedir = /usr datadir = /var/lib/mysql tmpdir = /tmp lc-messages-dir = /usr/share/mysql skip-external-locking skip-grant-tables

修改密碼

mysql> use mysql Database changed mysql> update user set authentication_string=password('123456') where user='root'; Query OK, 2 rows affected, 1 warning (0.01 sec) Rows matched: 2 Changed: 2 Warnings: 1mysql> flush privileges; Query OK, 0 rows affected (0.09 sec)mysql>

去掉剛才添加“skip-grant-tables” 然后重啟

deng@itcast:~$ sudo systemctl restart mysql deng@itcast:~$ mysql -h 192.168.13.143 -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3 Server version: 5.7.29-0ubuntu0.18.04.1 (Ubuntu)Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> quit Bye

06. 附錄

總結

以上是生活随笔為你收集整理的【数据库】Ubuntu18.04安装MySQL详解的全部內容,希望文章能夠幫你解決所遇到的問題。

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