linux之MySQL安装

安装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
以后就以此方式连接。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值