Ubuntu 安装MySQL8

安装mysql

$sudo apt-get install mysql-server -y

MySQL安全配置

$sudo mysql_secure_installation
Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

VALIDATE PASSWORD COMPONENT 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 component?

Press y|Y for Yes, any other key for No: y  #是否安装密码强度验证组件

There are three levels of password validation policy:

LOW    Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary                  file

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 2 #选择密码强度 ##上面选择不安装密码强度验证组件布显示这个
Please set the password for root here.

New password:   #设置root密码

Re-enter new password:  #确认root密码

Estimated strength of the password: 90 
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y  #是否确定使用上面的密码
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) : y  #是否删除匿名用户?
Success.  


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 #是否禁止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) : y #是否删除test数据库
 - Dropping test database...
Success.

 - Removing privileges on test database...
Success.

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 #是否现在重新加载特权表
Success.

All done! 

配置root身份登录及远程登录

上面配置好后,输入mysql -uroot -p 会报错

ERROR 1698 (28000): Access denied for user 'root'@'localhost'

解决方法:

上面步骤后输入sudo mysql进入mysql

$sudo mysql

在mysql shell里输入 

ALTER USER 'root'@'localhost' IDENTIFIED BY '你的密码' PASSWORD EXPIRE NEVER;
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '你的密码';
use mysql   #远程登录才需要操作
update user set host='%' where user='root';   #远程登录才需要操作
flush privileges;

这样就可以用root登录了,要远程登录还要配置ip

打开mysql配置文件/etc/mysql/mysql.conf.d/mysqld.cnf

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

在bind-address           = 127.0.0.1前面加个# 注释掉这行

重启Mysql

/etc/init.d/mysql restart

完成!!

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值