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

相关推荐
ss2736 小时前
PostgreSQL常见索引问题与解决方案
数据库·postgresql
小徐不徐说6 小时前
序列化与反序列化:把 C++ 对象可靠地保存下来
开发语言·数据库·c++·php
瀚高PG实验室7 小时前
发布端逻辑复制槽消失
数据库·postgresql·瀚高数据库
ss2738 小时前
PostgreSQL慢查询定位与优化
数据库·postgresql
香蕉大香蕉(06敬畏市场)8 小时前
MySQL 单点详解(07)
java·数据库·mysql·ai·博客·八股
smilejingwei9 小时前
TRAE 插件上新 | SQLazy:让 AI 写出可信复杂 SQL
数据库·人工智能·sql
我要见SA姐19 小时前
GitHub Actions 自动化:5 个真实运维提效案例
运维·数据库·机器学习·oracle·回归
传奇开心果编程9 小时前
【Jetpack Compose娓娓道来】第29课:状态容器与UI事件建模——把“散装状态”变成“可穷举的契约”
android·kotlin·移动开发·android jetpack·ui框架·开发范式·声明式ui
IT规划师10 小时前
百亿数据写入 MySQL:空间降维 × IO 降维 × 工程兜底
mysql·sqlsugar·.net10