ICode9

精准搜索请尝试: 精确搜索
首页 > 数据库> 文章详细

Ubuntu 安装 MySQL 5.7

2022-08-25 13:33:43  阅读:161  来源: 互联网

标签:sudo 5.7 Ubuntu user mysql MySQL password root


一、安装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

 

标签:sudo,5.7,Ubuntu,user,mysql,MySQL,password,root
来源: https://www.cnblogs.com/vipsoft/p/16623918.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有