首先下载了个windows版本的,在电脑上安装比较顺利(没有从官方下载,太慢了),网上一大堆教程,基本就是下一步下一步。
由于台式机已经装了Oracle,所以打算在自己的笔记本上安装mysql学习,也方便我到处折腾。
找了好久终于找到了dmg的安装文件,压缩包的实在是搞了半天没搞懂(百度下载的tar版本解压后有问题,而Oracle官方点击下载下不下来),后来终于在mysql的页面找到了dmg安装包的下载地址,不过页面地址却忘记了。大家好好找找还是能找到的。折腾到凌晨3点安装好后,测试基本SQL都没问题,可是新建用户却一直登陆不上:
mysql> create user azzot identified by 'chenxu123';
Query OK, 0 rows affected (0.01 sec)
mysql>
mysql> quit
Bye
chenxudeMacBook-Air:~ chenxu$ mysql -u azzo -p
Enter password:
ERROR 1045 (28000): Access denied for user 'azzo'@'localhost' (using password: YES)
密码是正确的,却无法登陆
后来发现我的SQL语句漏了一个比较重要的东西:
所以正确的命令应该如下
命令:CREATE USER 'username'@'host' IDENTIFIED BY 'password';
说明:username - 你将创建的用户名, host - 指定该用户在哪个主机上可以登陆,如果是本地用户可用localhost, 如果想让该用户可以从任意远程主机登陆,可以使用通配符%. password - 该用户的登陆密码,密码可以为空,如果为空则该用户可以不需要密码登陆服务器.
例子:
CREATE USER 'dog'@'localhost' IDENTIFIED BY '123456';
CREATE USER 'pig'@'192.168.1.101_' IDENDIFIED BY '123456';
CREATE USER 'pig'@'%' IDENTIFIED BY '123456';
CREATE USER 'pig'@'%' IDENTIFIED BY '';
CREATE USER 'pig'@'%';
重新创建用户后
mysql> create user 'azzotest'@'localhost' identified by 'chenxu321';
Query OK, 0 rows affected (0.01 sec)
chenxudeMacBook-Air:~ chenxu$ mysql -u azzotest -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 455
Server version: 5.6.26 MySQL Community Server (GPL)
Copyright (c) 2000, 2015, 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>
除此还有一种方法,由于我第一次创建的azzo用户是没有指定本地登陆还是远程登录,那么默认就是'%',查询用户表
点击(此处)折叠或打开
-
mysql> select host,user,password from mysql.user;
-
+---------------------------+-------+-------------------------------------------+
-
| host | user | password |
-
+---------------------------+-------+-------------------------------------------+
-
| localhost | root | |
-
| chenxudemacbook-air.local | root | |
-
| 127.0.0.1 | root | |
-
| ::1 | root | |
-
| localhost | | |
-
| chenxudemacbook-air.local | | |
-
| localhost | mysql | *CEB52BCA1740A8E9E3979A5BA6D0609023F0BD21 |
-
| % | azzo | *CEB52BCA1740A8E9E3979A5BA6D0609023F0BD21 |
-
+---------------------------+-------+-------------------------------------------+
- 8 rows in set (0.00 sec)

在群里咨询得知,可以在登陆的时候增加-h ip地址的选项,就可以登陆了。
不过我还没测试成功 - -,可能是我机器本身问题(mysql配置、防火墙等),或者本身这种方法就不行,后面继续学习吧。