Ubuntu 安装 MySQL 5.7
一、安装MySQL
1. 删除Mysql 数据库
sudo apt autoremove --purge mysql-server-* sudo apt remove mysql-server sudo apt autoremove mysql-server sudo apt remove mysql-common
2. 安装Mysql
sudo apt-get update #更新包
sudo apt install mysql-server-5.7
查看 MySQL 版本
sudo mysql -V
查看MySQL默认账号和密码
sudo cat /etc/mysql/debian.cnf
二、配置MySQL
sudo mysql_secure_installation
#1 VALIDATE PASSWORD PLUGIN can be used to test passwords... 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... Remove anonymous users? (Press y|Y for Yes, any other key for No) : N #4 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 #5 By default, MySQL comes with a database named 'test' that anyone can access... Remove test database and access to it? (Press y|Y for Yes, any other key for No) : N #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
三、查看mysql服务状态
systemctl status mysql.service
四、修改root账户认证方式
sudo cat /etc/mysql/debian.cnf # 查看 Password 后面的密码 mysql -u debian-sys-maint -p #进入 mysql 命令模式 mysql> use mysql;
mysql> select user,host,authentication_string from user; mysql> update mysql.user set authentication_string=password('密码') where user='root' and Host ='localhost'; mysql> update user set plugin='mysql_native_password'; //注意别更新错了,错了客户端工具就连不上了 mysql> select Host, User, plugin from user; mysql> flush privileges; mysql> quit;
五、配置远程访问mysql
修改配置文件,注释掉bind-address = 127.0.0.1
sudo vi /etc/mysql/mysql.conf.d/mysqld.cnf :wq mysql -uroot -p mysql> use mysql; mysql> update user set host='%' where user = 'root'; mysql> flush privileges;
#重启 sudo service mysql restart #查看状态 systemctl status mysql.service
本文来自博客园,作者:VipSoft 转载请注明原文链接:https://www.cnblogs.com/vipsoft/p/16623918.html
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· 清华大学推出第四讲使用 DeepSeek + DeepResearch 让科研像聊天一样简单!
· 实操Deepseek接入个人知识库
· CSnakes vs Python.NET:高效嵌入与灵活互通的跨语言方案对比
· Plotly.NET 一个为 .NET 打造的强大开源交互式图表库