Ubuntu安装mysql

尽量在所有命令前加上 sudo

安装

首先,可以查找系统的mysql (适用于mysql5.7版本)

sudo apt search mysql

Sorting... Done
Full Text Search... Done
mysql-server/bionic-updates,bionic-security 5.7.37-0ubuntu0.18.04.1 all
  MySQL database server (metapackage depending on the latest version)

mysql-server-5.7/bionic-updates,bionic-security 5.7.37-0ubuntu0.18.04.1 amd64
  MySQL database server binaries and system database setup

接下来,开始安装

sudo apt-get install mysql-server-5.7

查看mysql是否正常运行

sudo netstat -tap | grep mysql
tcp        0      0 localhost:mysql         0.0.0.0:*               LISTEN      29221/mysqld

 如果需要安装mysql 8.0版本,则需要额外下载,并使用如下命令安装查看

wget -c https://dev.mysql.com/get/mysql-apt-config_0.8.10-1_all.deb

sudo dpkg -i mysql-apt-config_0.8.10-1_all.deb

这时候,要执行一遍 sudo apt-get update,会遇到问题,

 sudo apt-get update

Get:1 http://repo.mysql.com/apt/ubuntu bionic InRelease [20.0 kB]
Hit:2 http://azure.archive.ubuntu.com/ubuntu bionic InRelease
Hit:3 http://azure.archive.ubuntu.com/ubuntu bionic-updates InRelease
Hit:4 http://azure.archive.ubuntu.com/ubuntu bionic-backports InRelease
Hit:5 http://azure.archive.ubuntu.com/ubuntu bionic-security InRelease
Err:1 http://repo.mysql.com/apt/ubuntu bionic InRelease
  The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 467B942D3A79BD29
Reading package lists... Done
W: GPG error: http://repo.mysql.com/apt/ubuntu bionic InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 467B942D3A79BD29
E: The repository 'http://repo.mysql.com/apt/ubuntu bionic InRelease' is not signed.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.

分别执行

sudo gpg --keyserver keyserver.ubuntu.com --recv 467B942D3A79BD29

sudo gpg --export --armor 467B942D3A79BD29 | sudo apt-key add -

或者请参见下一篇 

following signatures couldn‘t be verified because the public key is not available:NO_PUBKEY 467B942D_jack@london的博客-CSDN博客

然后接着安装

sudo apt-get install mysql-server

安装过程中会让你输入root密码

完后,可以查看mysql 8.0安装状态

mysql -V

sudo systemctl status mysql

ps -el | grep mysqld

连接

使用root帐户登录,默认密码为空

sudo mysql -u root -p

说明:记得带上root,否则会报错

mysql -u root -p
Enter password:
ERROR 1698 (28000): Access denied for user 'root'@'localhost'

接下来,对数据库进行初始化设置,可以根据自己选择y或No

sudo mysql_secure_installation

这其中会让设置新的密码。

检查mysql状态

sudo systemctl status mysql

可以再次登录数据库,测试设置的新密码

 sudo mysql -u root -p

mysql 5.7 配置远程访问

sudo vi /etc/mysql/mysql.conf.d/mysqld.cnf

注释该行

bind-address          = 127.0.0.1

保存退出后,重新登录进入mysql,授权命令

mysql> grant all on *.* to root@'%' identified by 'root' with grant option;
Query OK, 0 rows affected, 1 warning (0.01 sec)

mysql>
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql 8.0配置远程访问

mysql> use mysql;

mysql> update user set host='%' where user='root';

mysql> flush privileges;

大致如此

重启mysql并查看状态

sudo systemctl restart mysql

sudo systemctl status mysql

至此,可以用mysql workbench/ Navicat/ DBeaver等数据库连接工具连接该mysql。

参见:

Ubuntu18.04 安装MySQL_Weison Wei的博客-CSDN博客_ubuntu 安装mysql

Ubuntu18.04下安装MySQL - OpsDrip - 博客园

null, message from server: "Host 'xxxxxxx' is not allowed to connect to this MySQL server" - 简书

【MYSQL】如何解决 java.sql.SQLException:null,message from Server:"Host 'xxx' is not allowed to connect to this MySQL Server" - 逆火狂飙 - 博客园

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Ubuntu安装MySQL有以下步骤: 1. 首先,卸载掉原来的MySQL。可以执行以下命令来清理残留数据并验证原有主机上是否安装MySQL: - sudo apt-get autoremove --purge mysql-server - sudo apt-get remove mysql-server - sudo apt-get autoremove mysql-server - sudo apt-get remove mysql-common - dpkg -l | grep ^rc | awk '{print $2}' | sudo xargs dpkg -P 2. 更新软件并安装MySQL: - sudo apt-get install update - sudo apt-get install upgrade - sudo apt-get install mysql-server - sudo apt-get install mysql-client - sudo apt-get install libmysqlclient-dev [2] 3. 安装完成后,可以通过以下命令来查看安装情况: - sudo netstat -tap | grep mysql 这样就可以在Ubuntu上成功安装MySQL了。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [ubuntu篇---ubuntu安装mysql教程](https://blog.csdn.net/m0_46825740/article/details/128145298)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* [Ubuntu如何安装Mysql](https://blog.csdn.net/weixin_44430893/article/details/119296615)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值