RedHat下MySQL的基本使用方法分享

所属分类: 数据库 / Mysql 阅读数: 1878
收藏 0 赞 0 分享

1. 下载RPM安装包, 因为安装MySQL的时候,软件会需要一依赖关系, 所以建议把所有的安装包下载下载, 再依次安装所以的RPM包。

2. 在RedHat下安装后, root密码为空, 设置MySQL的 root密码, 用下面的命令来设置.

[nb@SIT ~]$ mysql -u root -p[newpassword]
3. 修改MySQL的root 密码, 用下面 的命令:

[nb@SIT ~]$ mysqladmin -u root -p[oldpasswrod] password[newpassword]
4. 用root登录MySQL, 输入下面的命令, 再输入密码, 就可以以root的身份登录到MySQL

[nb@SIT ~]$ mysql -u root -p
Enter password:
5. 出现下面的字符, 就表示成功登录到了MySQL,

Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 14
Server version: 5.5.14 MySQL Community Server (GPL)

Copyright (c) 2000, 2010, 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>
6. 显示当前已经存在的数据库,输入: show databases;

mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)
7. 创建一个新的数据库, 输入: create database [name];

mysql> create database mytest;
Query OK, 1 row affected (0.00 sec)

mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| mytest |
| performance_schema |
| test |
+--------------------+
5 rows in set (0.00 sec)
8. 删除一个已经存在的数据库, 输入: drop database [name];

mysql> drop database mytest;
Query OK, 0 rows affected (0.00 sec)

mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)
9. 创建一张表, 输入: create table [name] [option...]
显示表的内容: describe [table name];

mysql> create table device
-> (
-> id int,
-> pn varchar(8),
-> descript varchar(30)
-> );
Query OK, 0 rows affected (0.01 sec)

mysql> describe device;
+----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+-------+
| id | int(11) | YES | | NULL | |
| pn | varchar(8) | YES | | NULL | |
| descript | varchar(30) | YES | | NULL | |
+----------+-------------+------+-----+---------+-------+
3 rows in set (0.00 sec)
10. 向表里面添加数据, 输入: insert into [table_name] set option1=[value], option2=[value] ...

mysql> insert into device set id=1,pn="abcd",descript="this is a good device";
Query OK, 1 row affected (0.01 sec)

mysql> insert into device set id=2,pn="efgh",descript="this is a good device";
Query OK, 1 row affected (0.00 sec)
11. 查看表里面的内容, 输入: select [col_name] from [table_name]

mysql> select * from device;
+------+------+-----------------------+
| id | pn | descript |
+------+------+-----------------------+
| 1 | abcd | this is a good device |
| 2 | efgh | this is a good device |
+------+------+-----------------------+
2 rows in set (0.01 sec)
12. 选择性的查询表里的内容, * 是通配符, 表示所有的, 查询单项的时候, 输入: select * from [table_name] where opiont=[value];

mysql> select * from device where id=2;
+------+------+-----------------------+
| id | pn | descript |
+------+------+-----------------------+
| 2 | efgh | this is a good device |
+------+------+-----------------------+
1 row in set (0.00 sec)
13. 选择性查询表里的内容, 输入: select [option]...[option] from [table_name] where [option]=[value];

mysql> select id,descript from device where id=2;
+------+-----------------------+
| id | descript |
+------+-----------------------+
| 2 | this is a good device |
+------+-----------------------+
1 row in set (0.00 sec)

更多精彩内容其他人还在看

MySQL中按照多字段排序及问题解决

这篇文章主要介绍了MySQL中按照多字段排序及问题解决的方法,非常的实用,有需要的小伙伴可以参考下。
收藏 0 赞 0 分享

MySQL外键使用详解

两天有人问mysql中如何加外键,今天抽时间总结一下。mysql中MyISAM和InnoDB存储引擎都支持外键(foreign key),但是MyISAM只能支持语法,却不能实际使用。
收藏 0 赞 0 分享

Mysql中LAST_INSERT_ID()的函数使用详解

从名字可以看出,LAST_INSERT_ID即为最后插入的ID值,有了这个实用的函数,我们可以实现很多问题,下面我们就来深入探讨下。
收藏 0 赞 0 分享

MySql insert插入操作的3个小技巧分享

这篇文章主要介绍了MySql insert插入操作的3个小技巧分享,本文讲解了插入的数据来源自其他表、插入时排除(忽略)重复记录、插入时遇到重复记录做更新操作三个小技巧,需要的朋友可以参考下
收藏 0 赞 0 分享

mysql修改自增长主键int类型为char类型示例

这篇文章主要介绍了mysql修改自增长主键int类型为char类型示例,需要的朋友可以参考下
收藏 0 赞 0 分享

Windows下使用Cygwin编译MySQL客户端

这篇文章主要介绍了Windows下使用Cygwin编译MySQL客户端,本文详细的讲解了编译过程,需要的朋友可以参考下
收藏 0 赞 0 分享

MySQL数据库优化推荐的编译安装参数小结

这篇文章主要介绍了MySQL数据库优化推荐的编译安装参数小结,需要的朋友可以参考下
收藏 0 赞 0 分享

MySQL之Field‘***’doesn’t have a default value错误解决办法

这篇文章主要介绍了MySQL之Field‘***’doesn’t have a default value错误解决办法,需要的朋友可以参考下
收藏 0 赞 0 分享

php连接MySQL的两种方式对比

这篇文章主要介绍了php连接MySQL的两种方式对比,一种是原生的链接方式另外一种是PDO方式,附上示例,推荐给大家,有需要的小伙伴可以参考下
收藏 0 赞 0 分享

Mysql InnoDB删除数据后释放磁盘空间的方法

这篇文章主要介绍了Mysql InnoDB删除数据后释放磁盘空间的方法,Innodb数据库对于已经删除的数据只是标记为删除,并不真正释放所占用的磁盘空间,这就导致InnoDB数据库文件不断增长,本文就讲解释放磁盘空间的方法,需要的朋友可以参考下
收藏 0 赞 0 分享
查看更多