mysql初体验

  • 操作系统: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/mysql找到debian.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> 

你可能感兴趣的:(mysql初体验)