2019-02-15メモ-MariaDBパスワードリセット、スロークエリーログ

3156 ワード

mariadbパスワードのリセット
  • 一般ユーザのパスワードを変更する
  • MariaDB [mysql]>  use mysql;
    MariaDB [mysql]> update user set authentication_string=password("bbs?DXG123") where User='bbs' and host='localhost';
    
  • rootパスワードを変更(元のrootパスワードを知っている場合)
  • mysqladmin -uroot -proot password "root"
    
  • rootパスワードの変更(元のrootパスワードが分からない場合)
  • [root@linux2019 ~]# vi /etc/my.cnf
    skip-grant
    
    [root@linux2019 ~]# /etc/init.d/mysqld restart
    [root@linux2019 ~]# mysql -uroot    #               mariadb
    MariaDB [(none)]> use mysql;
    MariaDB [mysql]> update user set authentication_string=password("root") where User='root' and host='localhost';
    MariaDB [mysql]> exit;
    [root@linux2019 ~]# vi /etc/my.cnf  #         
    #skip-grant
    [root@linux2019 ~]# /etc/init.d/mysqld restart
    

    PS:mysql/mariadb新しいバージョンでパスワードフィールドをauthenticationに保存しました.stringフィールドでは、古いバージョンはpasswordフィールドにあります.
    MariaDBスロークエリーログ
    php-fpm構成のslowログと同様にmariadbのボトルネックの分析に役立ちます
    コンフィギュレーション
    #         
    MariaDB [(none)]> show variables like 'slow%';
    +---------------------+--------------------+
    | Variable_name       | Value              |
    +---------------------+--------------------+
    | slow_launch_time    | 2                  |
    | slow_query_log      | OFF                |
    | slow_query_log_file | linux2019-slow.log |
    +---------------------+--------------------+
    3 rows in set (0.002 sec)
    
    MariaDB [(none)]> show variables like 'datadir%';
    +---------------+--------------+
    | Variable_name | Value        |
    +---------------+--------------+
    | datadir       | /data/mysql/ |
    +---------------+--------------+
    1 row in set (0.002 sec)
    
    MariaDB [(none)]> show variables like 'long%';
    +-----------------+-----------+
    | Variable_name   | Value     |
    +-----------------+-----------+
    | long_query_time | 10.000000 |
    +-----------------+-----------+
    1 row in set (0.002 sec)
    
    [root@linux2019 ~]# vi /etc/my.cnf
    slow_query_log = ON
    slow_query_log_file = /data/mysql/linux2019-slow.log
    long_query_time = 2
    [root@linux2019 ~]# /etc/init.d/mysqld restart
    
    

    テスト
    MariaDB [(none)]> select sleep(5);  #     
    +----------+
    | sleep(5) |
    +----------+
    |        0 |
    +----------+
    1 row in set (5.001 sec)
    
    MariaDB [(none)]> exit
    Bye
    [root@linux2019 ~]# cat /data/mysql/linux2019
    linux2019.pid       linux2019-slow.log  
    [root@linux2019 ~]# cat /data/mysql/linux2019-slow.log 
    /usr/local/mysql/bin/mysqld, Version: 10.3.11-MariaDB-log (MariaDB Server). started with:
    Tcp port: 0  Unix socket: /tmp/mysql.sock
    Time		    Id Command	Argument
    # Time: 190214 11:46:40
    # User@Host: root[root] @ localhost []
    # Thread_id: 9  Schema:   QC_hit: No
    # Query_time: 5.000585  Lock_time: 0.000000  Rows_sent: 1  Rows_examined: 0
    # Rows_affected: 0  Bytes_sent: 63
    SET timestamp=1550116000;
    select sleep(5);
    

    PS
  • show processlist; #クエリー・キューの表示
  • show full processlist; #詳細表示
  • mysql-uroot-proot-e「show processlist」#-eオプションは、データベース
  • にログインすることなく、sql文をlinuxシステムで直接実行できます.