ubantu安装、卸载mysql

先更新依赖

sudo apt-get update

安装mysql服务和客户端

sudo apt-get install mysql-client mysql-server

查看mysql服务状态

sudo service mysql status
sudo mysql --version ##查看mysql的版本
sudo service mysql start ##如未启动可以执行该命令启动
sudo systemctl enable mysql    ##设置开机启动
sudo mysql_secure_installation ##初始化配置

以root登录mysql

sudo mysql -u root -p

修改root密码

以切换mysql数据库

use mysql;

查看用户名密码

select host, user, Password_reuse_history from mysql.user;

修改root密码,5.7~8.0以下版本

update user set authentication_string = password('123456789'), password_expired = 'N', password_last_changed = now() where user = 'root';
或者
ALTER user 'root'@'localhost' IDENTIFIED BY 'root123456';
# MySQL5.7新特性
update mysql.user set plugin="mysql_native_password";
flush privileges;  ##立即生效
quit; 

8.0新特性

update user set authentication_string='' where user='root';  ##先将字段置为空
ALTER user 'root'@'localhost' IDENTIFIED BY 'root';    ##修改密码
flush privileges;    ##立即生效
quit;

开启远程访问

首先修改文件mysqld.cnf,本人的mysql是通过apt安装的,所以该文件路径为/etc/mysql/mysql.conf.d/mysqld.cnf

vi /etc/mysql/mysql.conf.d/mysqld.cnf 
 ##找到bind-address属性,修改值为 0.0.0.0
创建远程访问root
5.7~8.0以前
use mysql;
CREATE USER 'root'@'%' IDENTIFIED BY 'root'; 
GRANT ALL ON *.* TO 'root'@'%'; 
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'root';
FLUSH PRIVILEGES;
如果用户已经存在则修改
use mysql;
update user set host='%' where user='root';
GRANT ALL ON *.* TO 'root'@'%'; 
alter user 'root'@'%' identified with mysql_native_password by '123456';
FLUSH PRIVILEGES;

8.0新特性

use mysql;
CREATE USER 'mysql.infoschema'@'%' IDENTIFIED BY '123456';
grant all privileges on *.* to 'mysql.infoschema'@'%'; 
flush privileges; 

查看用户名密码以及权限

select host,user from user; 

卸载mysql

本文使用的apt安装,则使用apt卸载,执行下面命令

sudo apt-get remove mysql-*

清理残留数据

dpkg -l |grep ^rc|awk '{print $2}' |sudo xargs dpkg -P

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值