安装mysql
安装指令
#yum install -y mysql-server
成功后启动mysql
[root@node04 ~]# service mysqld start
测试mysql是否成功
Please report any problems with the /usr/bin/mysqlbug script!
[ OK ]
Starting mysqld: [ OK ]
[root@node04 ~]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.1.73 Source distribution
Copyright (c) 2000, 2013, 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
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| test |
+--------------------+
3 rows in set (0.00 sec)
#显示数据库实例
show databases;
#使用数据库实例名为mysql的数据库
use mysql;
#显示这个库中有哪些表
show tables;
desc user;
mysql> select host,user,password from user;
+-----------+------+----------+
| host | user | password |
+-----------+------+----------+
| localhost | root | |
| node04 | root | |
| 127.0.0.1 | root | |
| localhost | | |
| node04 | | |
+-----------+------+----------+
5 rows in set (0.00 sec)
此时安装成功且可以使用了mysql了,但是从user表中看到host只限于本机使用,集群中的其他节点不能登录访问,所以要设置能让其他节点都能访问的用户。这里就简单设置成所有用户有所有的权限,然后都以root账号登录。
修改mysql的登录权限
修改MySQL登录权限,使得所有用户登录访问mysql,包括本地,远程,都可以用root/123的账密访问。
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123' WITH GRANT OPTION;
Query OK, 0 rows affected (0.00 sec)
mysql> select host,user,password from user;
+-----------+------+-------------------------------------------+
| host | user | password |
+-----------+------+-------------------------------------------+
| localhost | root | |
| node04 | root | |
| 127.0.0.1 | root | |
| localhost | | |
| node04 | | |
| % | root | *23AE809DDACAF96AF0FD78ED04B6A265E05AA257 |
+-----------+------+-------------------------------------------+
6 rows in set (0.01 sec)
授权后,在最后一行就会多了一个所有用户%,和对123加密后的密码。此时可以删除其他非%的用户。
delete from user where host!=’%’;
如果没有重启服务,就刷新
flush privileges;
重新登录后,
[root@node01 bin]# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
此时是登录不上mysql了,因为已经删除了其他用户,包括免密用户,所以需要带密码
#mysql -uroot -p
password:输入 123
以后就以此方式连接。