Centos安装mysql 8.0.17

安装

首先卸载已安装版本:
rpm -qa|grep -i mysql (检查有没有)
rpm -e mysql (删除)
1.下载安装:yum -y install sql-server
2.启动:systemctl start mysqld
3.查状态:systemctl status mysqld
4.创建root用户密码:mysqladmin -u root password “123456”;

数据库的用户管理

1.创建用户

create user 用户名@‘ip’ identified by ‘密码’

create user tom@‘localhost’ identified by ‘123456’; //创建tom用户,密码为123,只允许本地登录
create user jack@’%’ identified by ‘abc’; //创建jack用户,密码abc,允许任意ip登录

2.修改用户名

rename user 原用户名@‘ip’ to 新用户名

rename user tom@‘localhost’ to jack; //将user用户重命名为jack

3.删除用户

drop user 用户名@‘ip’

drop user tom@‘localhost’; //删除tom用户

4.修改密码

set password for 用户名@‘ip’=password(‘新密码’); (方法一)
update mysql.user set password=password(‘新密码’) where user=‘用户名’; (修改完之后 flush privileges 刷新权限)#方法一
mysqladmin -u root password “newpass” 适用于root未设置密码的时候
mysqladmin -u root -p password new_pass root设置了密码后,可以使用这个命令。回车后输入旧密码即可

#方法二
当MySQL<5.7版本时
use mysql;
update user set password=PASSWORD(“root_pass”) where user=“root”;
flush privileges;

当MySQL>=5.7版本时
use mysql;
update user set authentication_string=password(‘root_pass’) where user=‘root’;
flush privileges;

当MySQL>=8.0时,取消了 password() 函数,所以我们这里第二步new_pass可以先用其他版本的mysql的password函数生成秘钥,然后写入。
use mysql;
update user set authentication_string=new_pass where user=‘root’;
flush privileges;

5.基本操作

建立新数据库
create database test;  ← 建立名为test的数据库 (注意是否可以建立这个数据库是在上面建立新用户的时候就决定了的)
使用数据库
use test  ← 连接到数据库
show tables;  ← 查看数据库中已存在的表
删除测试账户
revoke all privileges on . from centospub@localhost;  ← 取消centospub用户对数据库的操作权限
delete from mysql.user where user=‘centospub’ and host=‘localhost’;  ← 删除centospub用户
select user from mysql.user where user=‘centospub’;  ← 查找用户centospub,确认已删除与否
flush privileges;  ← 刷新,使以上操作生效
删除数据库
drop database name 直接删除数据库,不提醒
mysqladmin drop databasename 删除数据库前,有提示。
表操作
show tables; 显示表
describe tablename; 表的详细描述
重命名表: mysql > alter table t1 rename t2;

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值