一、卸载原来的mysql:
卸载一:
输入:#rpm -qa | grep -i mysql
显示:
mysql-libs-5.1.52-1.el6_0.1.i686卸载方法:yum -y remove mysql-libs-5.1.52-1.el6_0.1.i686
卸载二:
输入:#rpm -qa | grep -i mysql
显示:
MySQL-client-5.1.62-1.glibc23.i386MySQL-server-5.1.62-1.glibc23.i386卸载方法:#rpm -ev MySQL-client-5.1.62-1.glibc23.i386 MySQL-server-5.1.62-1.glibc23.i386
二、安装
--安装Server端:
[root@rac2 software]# ls
MySQL-client-5.5.15-1.rhel5.x86_64.rpm
MySQL-devel-5.5.15-1.rhel5.x86_64.rpm
MySQL-embedded-5.5.15-1.rhel5.x86_64.rpm
MySQL-server-5.5.15-1.rhel5.x86_64.rpm
MySQL-shared-5.5.15-1.rhel5.x86_64.rpm
MySQL-shared-compat-5.5.15-1.rhel5.x86_64.rpm
MySQL-test-5.5.15-1.rhel5.x86_64.rpm
[root@rac2 software]# rpm -ivh MySQL-server-5.5.15-1.rhel5.x86_64.rpm
Preparing... ########################################### [100%]
1:MySQL-server ########################################### [100%]
PLEASE REMEMBER TO SET A PASSWORD FOR THEMySQL root USER !
To do so, start the server, then issue thefollowing commands:
/usr/bin/mysqladmin -u root password'new-password'
/usr/bin/mysqladmin -u root -h rac2password 'new-password'
Alternatively you can run:
/usr/bin/mysql_secure_installation
which will also give you the option ofremoving the test
databases and anonymous user created bydefault. This is
strongly recommended for productionservers.
See the manual for more instructions.
Please report any problems with the /usr/bin/mysqlbugscript!
[root@rac2 software]#
--- 安装客户端
[root@rac2 software]# rpm -ivh MySQL-client-5.5.15-1.rhel5.x86_64.rpm
Preparing... ########################################### [100%]
1:MySQL-client ###########################################[100%]
--- 安装share,dev 步骤同上,在这略过
2.3 其他操作
2.3.1 查看在时创建的mysql用户和mysql group:
[root@rac2 bin]# cat /etc/passwd|grep mysql
mysql:x:103:106:MySQLserver:/var/lib/mysql:/bin/bash
[root@rac2 bin]# cat /etc/group | grepmysql
mysql:x:106:
2.3.2 修改密码
--连接MySQL 报错:
[root@rac2 software]# mysql
ERROR 2002 (HY000): Can't connect to localMySQL server through socket '/var/lib/mysql/mysql.sock' (2)
--启动MySQL 后,在连正常:
[root@rac2 ~]# /etc/init.d/mysql start
Starting MySQL... [ OK ]
[root@rac2 init.d]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.15 MySQL CommunityServer (GPL)
Copyright (c) 2000, 2010, and/or itsaffiliates. All rights reserved.
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.
mysql>
--注意这里,因为MySQL默认没有密码,所以这里我们没有输入密码就直接连上了。
--修改密码,这个是安装Server 中提示的:
[root@rac2 ~]# /usr/bin/mysqladmin -u root password root
[root@rac2 ~]# mysql
ERROR 1045 (28000): Access denied for user'root'@'localhost' (using password: NO)
--修改密码之后,就提示要使用密码了。
[root@rac2 ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.5.15 MySQL CommunityServer (GPL)
Copyright (c) 2000, 2010, Oracle and/or itsaffiliates. All rights reserved.
Oracle is a registered trademark of OracleCorporation and/or its affiliates. Other names may be trademarks of theirrespective owners.
Type 'help;' or '\h' for help. Type '\c' toclear the current input statement.
mysql>
--输入密码后成功连接。
2.3.3 查看MySQL端口 3306, 这个是默认端口:
[root@rac2 ~]# netstat -nat|grep 3306
tcp 0 0 192.168.3.100:32842 192.168.3.100:3306 TIME_WAIT
tcp 0 0 :::3306 :::* LISTEN
2.3.4 设置开机自启动
--查看MySQL 开机自启动设置:
[root@rac2 ~]# chkconfig --list |grep mysql
mysql 0:off 1:off 2:on 3:on 4:on 5:on 6:off
这里的数字分别代表启动的不同模式,3是命令行,5是窗口。
--关闭开机自启动
[root@rac2 ~]# chkconfig mysql off
[root@rac2 ~]# chkconfig --list |grep mysql
mysql 0:off 1:off 2:off 3:off 4:off 5:off 6:off
--启用开机自启动:
[root@rac2 ~]# chkconfig mysql on
[root@rac2 ~]# chkconfig --list |grep mysql
mysql 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[root@rac2 ~]#
--将Mysql 从chkconfig服务里删除:
[root@rac2 ~]# chkconfig --del mysql
[root@rac2 ~]# chkconfig --list |grep mysql
--将Mysql 添加到chkconfig里:
[root@rac2 ~]# chkconfig --add mysql
[root@rac2 ~]# chkconfig --list |grep mysql
mysql 0:off 1:off 2:on 3:on 4:on 5:on 6:off
2.4 数据库操作
[root@rac2 ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.5.15 MySQL CommunityServer (GPL)
Copyright (c) 2000, 2010, Oracle and/or itsaffiliates. All rights reserved.
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.
--查看已经存在的数据库,这几个是安装时自动创建的
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)
--使用mysql 数据库
mysql> use mysql
Reading table information for completion oftable and column names
You can turn off this feature to get aquicker startup with -A
Database changed
--查看mysql 数据库下面的表
mysql> show tables;
+---------------------------+
| Tables_in_mysql |
+---------------------------+
| columns_priv |
| db |
| event |
| func |
| general_log |
| help_category |
| help_keyword |
| help_relation |
| help_topic |
| host |
| ndb_binlog_index |
| plugin |
| proc |
| procs_priv |
| proxies_priv |
| servers |
| slow_log |
| tables_priv |
| time_zone |
| time_zone_leap_second |
| time_zone_name |
| time_zone_transition |
| time_zone_transition_type |
| user |
+---------------------------+
24 rows in set (0.01 sec)
--创建数据库Dave
mysql> create database dave;
Query OK, 1 row affected (0.01 sec)
--在dave 数据库下面创建dave表:
mysql> use dave;
Database changed
mysql> create table dave(id int,namechar(20));
Query OK, 0 rows affected (0.01 sec)
--查看dave 表结构:
mysql> desc dave;
+-------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+----------+------+-----+---------+-------+
| id | int(11) | YES | | NULL | |
| name | char(20) | YES | | NULL | |
+-------+----------+------+-----+---------+-------+
2 rows in set (0.00 sec)
--向dave 表里插入2条记录:
mysql> insert into davevalues(1,'dave');
Query OK, 1 row affected (0.00 sec)
mysql> insert into davevalues(2,'anqing');
Query OK, 1 row affected (0.01 sec)
mysql> select * from dave;
+------+--------+
| id | name |
+------+--------+
| 1 | dave |
| 2 | anqing |
+------+--------+
2 rows in set (0.00 sec)
--update 表:
mysql> update dave set name='david dai'where id=1;
Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select * from dave;
+------+-----------+
| id | name |
+------+-----------+
| 1 | david dai |
| 2 | anqing |
+------+-----------+
2 rows in set (0.00 sec)
--drop 表:
mysql> drop table dave;
Query OK, 0 rows affected (0.01 sec)
--drop 数据库:
mysql> drop database dave;
Query OK, 0 rows affected (0.00 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.01 sec)
至此,操作结束。