mysql初体験

3634 ワード

  • オペレーティングシステム:Ubuntu 16.4.0 LTS
  • mysqlサーバのインストール
    sudo apt-get update sudo apt-get install mysql-server
    サービスの開始
    sudo service mysql status sudo service mysql start
    バージョンの検証
    $ mysqladmin --version
    mysqladmin  Ver 8.42 Distrib 5.5.54, for debian-linux-gnu on x86_64
    

    rootパスワードの設定:/etc/mysqldebian.cnfを見つけ、管理アカウントパスワードを表示します.
    $ sudo cat debian.cnf
    # Automatically generated for Debian scripts. DO NOT TOUCH!
    [client]
    host     = localhost
    user     = debian-sys-maint
    password = VUESAzkIpf7ckpnA
    socket   = /var/run/mysqld/mysqld.sock
    [mysql_upgrade]
    host     = localhost
    user     = debian-sys-maint
    password = VUESAzkIpf7ckpnA
    socket   = /var/run/mysqld/mysqld.sock
    basedir  = /usr
    

    mysqlにログインするには:
    $ mysql -u debian-sys-maint -p
    Enter password: 
    ERROR 1045 (28000): Access denied for user 'debian-sys-maint'@'localhost' (using password: YES)
    zhanghaipeng@zhanghaipeng-Lenovo-K2450:/etc$ mysql -u debian-sys-maint -p
    Enter password: 
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 61
    Server version: 5.5.54-0ubuntu0.14.04.1 (Ubuntu)
    
    Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
    
    Oracle is a registered trademark of Oracle Corporation and/or its
    affiliates. Other names may be trademarks of their respective
    owners.
    
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    
    mysql> 
    
    

    rootパスワードの変更:
    mysql> show databases;
    +--------------------+
    | Database           |
    +--------------------+
    | information_schema |
    | mysql              |
    | performance_schema |
    +--------------------+
    3 rows in set (0.00 sec)
    
    mysql> use mysql;
    Reading table information for completion of table and column names
    You can turn off this feature to get a quicker startup with -A
    
    Database changed
    mysql> select host,user,password from user;
    +---------------------------+------------------+-------------------------------------------+
    | host                      | user             | password                                  |
    +---------------------------+------------------+-------------------------------------------+
    | localhost                 | root             | *9D244EF0DC2E16FC2EF469372F5E24ED87C94ECF |
    | zhanghaipeng-lenovo-k2450 | root             | *9D244EF0DC2E16FC2EF469372F5E24ED87C94ECF |
    | 127.0.0.1                 | root             | *9D244EF0DC2E16FC2EF469372F5E24ED87C94ECF |
    | ::1                       | root             | *9D244EF0DC2E16FC2EF469372F5E24ED87C94ECF |
    | localhost                 | debian-sys-maint | *B885D6BF31D9DBCCD1ACA8EBE20A5D381FE0CDAB |
    +---------------------------+------------------+-------------------------------------------+
    5 rows in set (0.00 sec)
    
    mysql> update user set password=password('***') where user='root';
    Query OK, 0 rows affected (0.00 sec)
    Rows matched: 4  Changed: 0  Warnings: 0
    
    mysql> 
    
    

    現在のログインユーザーを終了し、rootアカウントでログインし直しました.
    $ mysql -u root -p
    Enter password: 
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 63
    Server version: 5.5.54-0ubuntu0.14.04.1 (Ubuntu)
    
    Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
    
    Oracle is a registered trademark of Oracle Corporation and/or its
    affiliates. Other names may be trademarks of their respective
    owners.
    
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    
    mysql>