centos上安装Mysql

 

 

1 安装环境:

a) CentOS release 5.8

b) 查看当前linux系统版本:

root@master conf]# lsb_release -a
LSB Version:    :core-4.0-ia32:core-4.0-noarch:graphics-4.0-ia32:graphics-4.0-noarch:printing-4.0-ia32:printing-4.0-noarch
Distributor ID: CentOS
Description:    CentOS release 5.8 (Final)
Release:        5.8
Codename:       Final

 

 

2 安装方式:  yum在线安装

 

 

3 安装流程:

如下MySQL安装是在master机器上安装的:

[root@master local]# yum install mysql-server   安装
...
Dependency Installed:
  mysql.i386 0:5.0.95-5.el5_9         perl-DBD-MySQL.i386 0:3.0007-2.el5        
  perl-DBI.i386 0:1.52-2.el5         

Complete!
[root@master local]# service mysqld start   启动mysql
...
                                                           [  OK  ]
Starting mysqld:                                           [  OK  
[root@master local]# service mysqld status
mysqld (pid 27645) is running...
[root@master local]# mysql -uroot
mysql> use mysql;
mysql> show tables;  
mysql> select password,user from user;
+----------+------+
| password | user |
+----------+------+
|          | root | 
|          | root | 
|          | root | 
|          |      | 
|          |      | 
+----------+------+

mysql> update user set password=password('admin')   ---->  给usr表设置加密密码
    -> ;
mysql> select password,user from user;
+------------------+------+
| password         | user |
+------------------+------+
| 43e9a4ab75570f5b | root | 
| 43e9a4ab75570f5b | root | 
| 43e9a4ab75570f5b | root | 
| 43e9a4ab75570f5b |      | 
| 43e9a4ab75570f5b |      | 
+------------------+------+
mysql> flush privileges;       ---->  设置生效 并退出MySQL
Query OK, 0 rows affected (0.00 sec)

mysql> exit;
Bye

[root@master local]# mysql -uroot -padmin     ---->  重新以有密码方式登录MySQL
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4


给集群别的机器设置当前安装的MySQL访问授权:
解释如下:
mysql> grant all on *.* to 'root'@'%' identified by 'admin';   
授予所有权限(all 比如增删改查) 在(on) 所有的表.所有的数据库 
给(to) root用户@所有机器上的(%表示) 对应的密码是 admin
这样对集群中所有用户为root 密码为admin的用户都能对当前安装的MySQL
内所有数据库和表都授予所有操作权限了。

命令如下:
mysql> grant all on *.* to 'root'@'%' identified by 'admin';
Query OK, 0 rows affected (0.10 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)


这样,假如我在103机器上也安装了MySQL服务(此时103机器的MySQL服务可以不启动),
[root@sliver103 network-scripts]#  mysql -hmaster -uroot -padmin
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.0.95 Source distribution
也可以进入到master的MySQL内执行命令。

 

 

 

4  常见报错:

 

a) Ignoring query to other XXX

[root@master local]# mysql -root
mysql> show databases;
Ignoring query to other database
mysql> show tables;
Ignoring query to other database
mysql> exit;          
Bye


错误原因:

折腾了半天才发现原来是在连接mysql时没有"-u"参数导致的
D:\Program Files\MySQL\MySQL Server 5.6\bin>mysql -uroot

重新连接mysql 加上-u参数 一切正常
[root@master local]# mysql -uroot

 

你可能感兴趣的:(centos)