1. 程式人生 > >Python - - MySQL資料庫 - - 操作錦集

Python - - MySQL資料庫 - - 操作錦集

  • :環境配置資訊,系統環境CentOS 7.4,資料庫版本 mysql-5.7.24

1,跳過授權表

# 在命令列跳過授權表命令
mysqld_safe --skip-grant-tables &

# 在 my.cnf 檔案配置跳過授權表命令
[mysqld]
skip-grant-tables

2,更改root密碼

# 方法一:
update mysql.user set authentication_string=password('root') where user='root' and host='localhost';
flush privileges;

# 報錯如下:使用方法二
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
# 方法二:
alter user user() identified by "root";
flush privileges;

3,建立新使用者並授權

# 授權本地登入
grant all privileges on *.* to [email protected] identified by 'test';

# 授權遠端登入
grant all privileges on *.* to [email protected]'%' identified by 'test';

4, 通過 Navicat 建立資料庫報錯

# 報錯如下
[Err] 1055 - Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated column 'information_schema.PROFILING.SEQ' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

# 查詢
select version(), @@sql_mode;
# 修改
SET sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY','')); 

5,查死鎖

show engine innodb status \G;

select * from information_schema.INNODB_TRX;