1. centos6.5安装mysql5版本
1.1 以su超级用户,安装Mysql数据库
[st01@master ~]$ rpm -ivh MySQL-server-5.5.48-1.linux2.6.i386.rpm--force --nodeps
1.2 启动Mysql数据库
[root@master st01]# service mysql start
1.3、安装Mysql客户端
[root@master st01]# rpm -ivh MySQL-client-5.5.48-1.linux2.6.i386.rpm --force --nodeps
1.4 进入Mysql
[root@master st01]# mysql
1.5 设置密码123456,展示所有数据库
mysql> set password for 'root'@'localhost' = password('123456');
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
1.6 进入数据库test
mysql> use test
Database changed
1.7 创建数据库表
mysql> create table hello(id int);
Query OK, 0 rows affected (0.02 sec)
mysql> show tables;
+----------------+
| Tables_in_test |
+----------------+
| hello |
+----------------+
1 row in set (0.00 sec)
mysql> exit
Bye
1.8 重新输入密码123456,进入数据库
[root@master hive]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 22
Server version: 5.5.48 MySQL Community Server (GPL)
Copyright (c) 2000, 2016, 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> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| hive |
| mysql |
| performance_schema |
| test |
+--------------------+
2. 数据的基本操作
[stu@localhost ~]$ su
密码:
[root@localhost stu]# mysql -u root -p
Enter password: 123456
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.5.48 MySQL Community Server (GPL)
Copyright (c) 2000, 2016, 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.
2.1 查看数据库
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.02 sec)
2.2 创建数据库
mysql> create database mbdb1;
Query OK, 1 row affected (0.00 sec)
删除数据库:
mysql> drop database mbdb1;
Query OK, 0 rows affected (0.03 sec)
mysql> create database mydb1;
Query OK, 1 row affected (0.01 sec)
创建一个utf8编码的数据库:
mysql> create database mydb2 character set utf8;
Query OK, 1 row affected (0.00 sec)
mysql> show create database mydb2;
+----------+----------------------------------------------------------------+
| Database | Create Database |
+----------+----------------------------------------------------------------+
| mydb2 | CREATE DATABASE `mydb2` /*!40100 DEFAULT CHARACTER SET utf8 */ |
+----------+----------------------------------------------------------------+
1 row in set (0.00 sec)
2.3 进入数据库
mysql> use mydb2;
Database changed
2.4 创建表
create table student (
id int,
name varchar(20),
chinese double,
english double,
math double);
mysql> create table student(
-> id int,
-> name varchar(20),
-> chinese double,
-> english double,
-> math double
-> );
Query OK, 0 rows affected (0.04 sec)
2.5 写入表数据
insert into student(id,name,chinese,english,math)
values(1,'张三',78.8,98,66);
insert into student(id,name,chinese,english,math)
values(2,'李四',88.5,68,96);
mysql> insert into student(id,name,chinese,english,math)
-> values(1,'张三',78.8,98,66);
Query OK, 1 row affected (0.00 sec)
mysql> insert into student(id,name,chinese,english,math)
-> values(2,'李四',88.5,68,96);
Query OK, 1 row affected (0.03 sec)
mysql> select * from student;
+------+--------+---------+---------+------+
| id | name | chinese | english | math |
+------+--------+---------+---------+------+
| 1 | 张三 | 78.8 | 98 | 66 |
| 2 | 李四 | 88.5 | 68 | 96 |
+------+--------+---------+---------+------+
2 rows in set (0.01 sec)
3. 安装MYSQL问题解决
3.1 以su超级用户,检查mysql运行状态
[root@localhost 桌面]# service mysql status
SUCCESS! MySQL running (2389)
3.2 检查mysql安装情况
[root@localhost 桌面]# rpm -qa|grep mysql
mysql-libs-5.1.73-5.el6_6.i686
3.3 卸载
[root@localhost 桌面]# rpm -e mysql-libs-5.1.73-5.el6_6.i686