Oracle is a registered trademark of OracleCorporation and/or its
affiliates. Other names may be trademarksof their respective
owners.
Type 'help;' or '\h' for help. Type '\c' toclear the current input statement.
(4) 输入修改root密码SQL语句
mysql> UPDATEuser SET Password=PASSWORD('passok') where USER='root';
Query OK, 4 rows affected (0.04 sec)
Rows matched: 4 Changed: 4 Warnings: 0
(5) 输入数据刷新命令
mysql> FLUSHPRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
(6) 退出
mysql> quit
Bye
(7) 启动MYSQL
[root@bogon 桌面]# service mysql start
Starting MySQL SUCCESS!
?
登录mysql,查看所有数据库:
[root@bogon 桌面]# mysql -u root -p
mysql> show databases;
ERROR 1820 (HY000):You must SET PASSWORD before executing this statement
?
还是有错误啊,提示要再设置一下密码:
mysql> SETPASSWORD = PASSWORD('passok');
Query OK, 0 rows affected (0.00 sec)
显示数据库:
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)
进入数据库创建表、显示表:
mysql> use test;
Database changed
mysql> show tables;
Empty set (0.02 sec)
mysql>create table testTable(name char(15) not null,passwd char(15) not null);
Query OK, 0 rows affected (0.87 sec)
mysql> show tables;
+----------------+
| Tables_in_test |
+----------------+
| testTable |
+----------------+
1 row in set (0.00 sec)
?
备注:我的设置的密码是“passok”。大家在执行showdatabases收到错误ERROR 1820 (HY000): You must SET PASSWORD before executing this statement后也可以试试以下面方式登录mysql来执行showdatabases是否就不会有这个错误,我没有条件测试了:
登录MySQL界面:mysql –uroot -p(修改的新密码)
例如:mysql -u root -p123456
?
mysql安装后三个主要的目录及其功能:
/var/lib/mysql 数据库文件
/usr/share/mysql 命令及配置文件
/usr/bin mysqladmin、mysqldump等命令
?
6. windows7上使用workbench连接到远端MySQL Server
(1) 下载安装workbench(MySQL Workbench 6.2.4 MSI for Windows x86(64bit))
(2) Windows下安装mysql workbench需要具备以下环境:
Microsoft .NET Framework 4 Client Profile
Microsoft Visual C++ 2013 RedistributablePackage (x64)
第一个就不用说了,第二个下载地址在:
http://www.microsoft.com/zh-CN/download/details.aspx?id=40784
(3)安装完成之后打开,进行连接配置:

发现连不上。
打开cmd命令行输入telnet 192.168.1.108 3306也提示连接不上(BTY:windows7默认没有安装telnet,需要通过控制面板中的打开或者关闭windows功能来打开telnet客户端功能)。
?
如果要想远端访问MYSQL数据库,还需要:
(1) 给指定用户赋予远端访问mysql数据库的权限;
(2) 配置防火墙放开对3306端口的限制;
?
1给指定用户赋予远端访问mysql数据库的权限
授权命令是:
grant 权限1,权限2,…权限n on 数据库名.表名 to用户名@用户地址 identified by‘口令’
[root@bogon 桌面]# mysql -uroot-ppassok -e "GRANT ALL PRIVILEGES ON *.* TO'root'@'%' IDENTIFIED BY 'passok' WITH GRANT OPTION;"
Warning: Using a password on the commandline interface can be insecure.
用root用户的身份执行grant命令(-e参数表示执行一段sql命令),含义是:把在所有数据库的所有表的所有权限赋值给位于所有IP地址的root用户。如果你只想让位于192.168.1.108机器上面的root用户访问,命令如下:
mysql -uroot -ppassok -e "GRANT ALL PRIVILEGES ON *.* TO'root'@'192.168.1.108' IDENTIFIED BY 'passok' WITH GRANT OPTION;"
?
2 配置防火墙放开3306端口的限制
CentOS 7.0版本的防火墙,默认使用的是firewall,与之前的版本使用iptables是不一样,经过我的测试,只要firewall处于开启状态,就不可能远端访问MYSQL数据库。
首先将firewall关闭:
[root@bogon 桌面]# systemctl stop firewalld.service #停止firewall
[root@bogon 桌面]# systemctl disable firewalld.service #禁止firewall开机启动
CentOS虽然默认的不是iptables,但是也是已经安装好的,然后我按照网上的方法,为3306端口配置开放规则:
[root@bogon 桌面]# vi /etc/sysconfig/iptables
# sample configuration for iptables service
# you can edit this manually or usesyst