【mysql】常用命令

一 系统mysql用户密码查询

1、在工程目录如/usr/local/httpd/下的*.php中查找类似有db.inf的文件

以php为例。

2、在代码文件中确认有数据库连接的的功能实现

例如:

复制代码
$dbconf   = parse_ini_file('/usr/local/httpd/conf/db.inf');
$link = mysql_connect($dbconf['db_address'],$dbconf['db_username'],$dbconf['db_password']);
mysql_select_db('username',$link);

3、cat /usr/local/httpd/conf/db.inf可看到用户名密码,例如:

db_address=localhost

db_username=user01

db_password=pass

db_name=dbname01

4、登录验证:

/usr/local/mysql/bin/mysql -u user01 -ppass

二 不知道mysql root密码的情况下再增加一个超级用户办法【简要说明】

1 杀死原有进程

kill -9 mysql进程

2 启动mysql无权限表模式

/usr/local/mysql/bin/mysqld_safe --datadir=/mysql_data --user=mysql --pid-file=/mysql_data/mysql.pid --skip-grant-tables &

3 不需要口令即可登录mysql:

/usr/local/mysql/bin/mysql

以上无权限表模式启动后可能要稍等片刻,才能执行/usr/local/mysql/bin/mysql

否则会报ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

4 新建名为admin的超级用户

mysql> GRANT ALL PRIVILEGES ON . TO admin@localhost IDENTIFIED BY 'xxxxxx' WITH GRANT OPTION;

GRANT ALL PRIVILEGES ON . TO admin@localhost IDENTIFIED BY 'xxxxxx' WITH GRANT OPTION;无法执行,

ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement

mysql> insert into mysql.user(Host,User,Password) values("%","admin",password("xxxxxx"));

Query OK, 1 row affected, 3 warnings (0.00 sec)

mysql> flush privileges; <-------------------------------------------重要

Query OK, 0 rows affected (0.00 sec)

mysql> GRANT ALL PRIVILEGES ON . TO admin@localhost IDENTIFIED BY 'xxxxxx' WITH GRANT OPTION;

Query OK, 0 rows affected (0.00 sec)

mysql> GRANT ALL PRIVILEGES ON . TO admin@"%" IDENTIFIED BY 'xxxxxx' WITH GRANT OPTION;

Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec)

$ /usr/local/mysql/bin/mysql -uadmin -pxxxxx;

mysql> use mysql

Database changed

mysql> select * from user;

三 查看数据库概况

1 数据库版本

select VERSION()

或

mysql --version

或简写为:

mysql -V

或

2 查看变量情况

mysql> show variables like '%char%';

±-------------------------±---------------------------------+

| Variable_name | Value |

±-------------------------±---------------------------------+

| character_set_client | utf8 |

| character_set_connection | utf8 |

| character_set_database | utf8 |

| character_set_filesystem | binary |

| character_set_results | utf8 |

| character_set_server | utf8 |

| character_set_system | utf8 |

| character_sets_dir | /usr/local/mysql/share/charsets/ |

±-------------------------±---------------------------------+

8 rows in set (0.00 sec)

3 查看用户情况

mysql> select * from user;

四 授权

1 授权查询和更新权限

GRANT SELECT ON db01.table01 TO 'user01'@'%' IDENTIFIED BY 'password';

GRANT UPDATE ON db01.table01 TO 'user01'@'%' IDENTIFIED BY 'password';

相关推荐
djjjx.9 小时前
Mysql数据库基础篇(八):详细讲解复合查询、多表查询、自连接、多行、多列子查询与合并查询
数据库·mysql
Wellijohn10 小时前
一个 Android 老兵的十年开源路:从 167 star 的滑动控件,到本地优先的 AI Agent
android·人工智能·开源
CoderYanger14 小时前
Java EE 进阶:9.MyBatis 操作数据库(进阶)(第八弹):MyBatis Generator
java·数据库·spring boot·spring·java-ee·tomcat·mybatis
好的佩奇15 小时前
Dart 之元数据与注解
android·flutter·dart
MSTcheng.15 小时前
【MySQL】MySQL数据库——表的操作
数据库·mysql·adb
FungLeo15 小时前
FengCMS · PHP+MySQL 升级实录 · 内容写入一致性:锁等待超时与跨模型子树删除竞态
开发语言·mysql·php·工程实践·fengcms
Yeats_Liao16 小时前
物联网平台MongoDB实战|(一)为什么选择MongoDB
数据库·物联网·mongodb
ZhengEnCi16 小时前
覆盖索引是什么:用借书和外卖看懂回表这件事
sql·mysql·postgresql
三少爷的鞋16 小时前
很多开发者把物理上的分层,当成了架构
android
鹤落晴春16 小时前
MySQL日志梳理
运维·数据库·mysql