ubuntu20.04安装mysql8.0

1.通过apt 安装MySQL

#命令1
sudo apt-get update
#命令2
sudo apt-get install mysql-server

2. 配置MySQL

2.1 配置初始化信息

sudo mysql_secure_installation

配置说明:

weison@ubuntu19-04:~$ 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?

Press y|Y for Yes, any other key for No: N(选择N,不会进行密码的强校验)
Please set the password for root here.

New password: 

Re-enter new password: 
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(选择N,不删除匿名用户)

 ... skipping.


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(选择N,允许root远程连接)

 ... skipping.
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(选择N,不删除test数据库)

 ... skipping.
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(选择Y,修改权限立即生效)
Success.

All done! 

2.2 配置访问权限

在Ubuntu下MySQL缺省是只允许本地访问的,使用workbench连接工具是连不上的;
如果你要其他机器也能够访问的话,需要进行配置;

2.2.1 配置远程访问

# 登陆mysql
sudo mysql -uroot -p
#切换数据库
use mysql;
#查询用户表命令:
select User,authentication_string,Host from user;

访问权限说明:host默认都是localhost访问权限

localhost本地连接
%本地+远程连接
use mysql;

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

#刷新cache中配置
flush privileges;  

1. 编辑mysql配置文件,把其中bind-address = 127.0.0.1注释了

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

2. 重启mysql

/etc/init.d/mysql restart
或
sudo service mysql restart

3.修改mysql密码

ALTER USER 'root'@'%' IDENTIFIED WITH MYSQL_NATIVE_PASSWORD BY 'root';

//root为密码

CentO系统 宝塔安装mysql8.0之后操作:

1.绕过密码登录

1.命令行输入vi /etc/my.cnf
2.按下键盘i,切换insert模式(此操作必须切换英文输入法)
3.在[mysqld]下面添加一行skip-grant-tables

如下图所示

 按下ESC键,输入:wq 然后回车退出编辑模式。:是指令符,w是保存指令,q是退出指令

2.重启mysql服务

systemctl restart mysqld

3.修改root可以远程访问

use mysql;

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

#刷新cache中配置
flush privileges;  

4.修改mysql密码

ALTER USER 'root'@'%' IDENTIFIED WITH MYSQL_NATIVE_PASSWORD BY 'root';

//root为密码

5.重启mysql服务

systemctl restart mysqld

  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值