【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';

相关推荐
今夜星辉灿烂几秒前
异构数据库数据同步最佳实践
数据库·elasticsearch
恋猫de小郭6 分钟前
Flutter 里的 Layer 解析,带你了解不一样角度下的 Flutter 渲染逻辑
android·前端·flutter
vivo高启强8 分钟前
FD 泄露引发的AGP8 build 失败问题
android
电商API_1800790524714 分钟前
微店商品详情接口micro.item_get请求参数响应参数解析
大数据·数据库·人工智能·爬虫
用户20187928316741 分钟前
Binder 事务失败(FAILED BINDER TRANSACTION)
android
qq_312920111 小时前
MySQL在Linux环境下的性能调优
linux·mysql·adb
柿蒂1 小时前
Android图片批量添加处理优化:从「30」秒缩短至「4.4」秒
android·android jetpack
····懂···2 小时前
开源数据库PostgreSQL专家技术
数据库·postgresql·开源
Asu52022 小时前
思途SQL学习 0729
数据库·sql·学习
北亚数据恢复2 小时前
服务器数据恢复—RAID上层部署的oracle数据库数据恢复案例
数据库·oracle·服务器数据恢复·北亚数据恢复