当前位置: 移动技术网 > IT编程>数据库>Mysql > RedHat下MySQL的基本使用方法分享

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

2017年12月12日  | 移动技术网IT编程  | 我要评论

昂首挺立,杜志浩,丁玉祥物理网

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)

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网