Linux系统下安装Mysql数据库
大概就下面几个步骤:
1.挂载磁盘
mount /dev/cdrom /mnt
说明已经挂载了
2. 安装mysql
yum install mysql-server -y
3. 启动mysql服务
service mysqld start
4. 验证是否安装成功
[[email protected] ~]# 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>
5.查看当前数据库
mysql> show databases
-> ;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| test |
+--------------------+
3 rows in set (0.00 sec)
6. 给数据库设置权限(为什么?因为可能mysql单独在一个节点上,其他节点需要访问mysql,就必须设置权限)
use mysql;
mysql> select host,user,password from user;
在这里看到默认的权限信息,密码全部都是空,host都是本机,用户名为root。这也就是为什么刚才直接敲mysql就可以登录数据库的原因了,这种权限很明显是不行的,很容易遭到破坏。
设置权限:
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123' WITH GRANT OPTION;
flush privileges;
7.这个时候再去看user表,发现多了一条权限,然后把之前的权限删除即可。
delete from user where host!='%';
flush privileges;
8. 检验权限
退出mysql,后再敲mysql:
发现已经有权限问题了。
[[email protected] ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
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>