标签:登录 默认 执行 丢失 local status com pass mmu
安装
# yum install mysql-community-server
启动MySQL服务
# systemctl start mysqld.service
检查MySQL服务状态
# systemctl status mysqld.service
查看root初始密码
# grep ‘temporary password‘ /var/log/mysqld.log
本地MySQL客户端登录
# mysql -uroot -p
重置root登录密码
> alter user ‘root‘@‘localhost‘ identified by ‘MyNewPass4!‘;
> flush privileges;
语法: mysql -h 主机地址 -u 用户名 -p 用户密码
# mysql -u root -p
必须停止服务
# systemctl stop mysqld.service
修改配置文件
# vim /etc/my.cnf
在最后一行添加:skip-grant-tables启动服务
# systemctl start mysqld.service
登录账户并修改密码
# msyql -uroot -p
> flush privileges;(该步骤必须有,否则会报无法执行修改密码操作)
> alter user ‘root‘@‘localhost‘ identified by ‘New123*‘;
撤销对配置文件修改,重启mysql服务器
在修改密码期间数据库不受保护。
允许本地IP访问localhost, 127.0.0.1
> create user ‘naruto‘@‘localhost‘ identified by ‘123456‘;
允许外网IP访问
> create user ‘naruto‘@‘%‘ identified by ‘123456‘
刷新授权
> flush privileges
删除用户naruto
> drop user ‘naruto‘@‘localhost‘;
查看naruto权限
> show grants for ‘naruto‘@‘localhost‘;
授予在所有表上全部权限
> grant all privileges on *.* to ‘naruto‘@‘localhost‘;
授权在test库上所有表读写权限
> grant select,insert on test.* to ‘naruto‘@‘localhosst‘;
刷新权限
> flush privileges;
回收部分权限
> revoke insert,select on *.* from ‘naruto‘@‘localhost‘;
回收全部权限
> revoke all on *.* from ‘naruto‘@‘localhost‘;
> select version()\g
> show databases;
> use <数据库名>;
> show tables;
方法一
> create database test_db;
方法二
# mysqladmin -u root -p create test_db
方法一
> drop database test_db;
方法二
# mysqladmin -u root -p drop test_db
> create table table_name (column_name column_type);
> desc <表名>;
> describe <表名>;
> show columns from <表名>;
> show create table <表名>;
> drop table table_name;
> insert into table_name (field1, field2, .., fieldn)
-> values (value1, value2, ..., valuen);
> select column_name, column_name
-> from table_name
-> [where Clause]
-> [limit N][offset M]
暂且这样
标签:登录 默认 执行 丢失 local status com pass mmu
原文地址:https://www.cnblogs.com/eat-and-die/p/10193432.html