$ ls ~yifei/notes/

在 Ubuntu 上安装 MySQL

Posted on:

Last modified:

安装

sudo apt -y install mysql-server

默认账号密码:

cat /etc/mysql/debian.cnf

或者直接通过 sudo mysql 就可以进去。这是因为默认情况下 root 用户是通过 sudo 来校验的, 而不需要密码,我们可以改成通过密码校验的方式:

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '';
FLUSH PRIVILEGES;

需要把 ubuntu 绑定地址改为 0.0.0.0。在 /etc/mysql/mysql.conf.d/mysqld.cnf 中注释掉 bind-address=127.0.0.1 行

开启 root 的远程登录:

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password';

在 8.0 以上需要显示创建 root 用户,见参考资料。

参考

  1. https://stackoverflow.com/questions/11223235/mysql-root-access-from-all-hosts
WeChat Qr Code

© 2016-2022 Yifei Kong. Powered by ynotes

All contents are under the CC-BY-NC-SA license, if not otherwise specified.

Opinions expressed here are solely my own and do not express the views or opinions of my employer.

友情链接: MySQL 教程站