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

 更新时间:2011年08月06日 22:23:40   作者:  
RedHat 下MySQL安装,简单设置以用基本的使用方法,需要的朋友可以参考下。

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)

相关文章

  • mysqldump加-w参数备份数据时需要注意的事项

    mysqldump加-w参数备份数据时需要注意的事项

    这篇文章主要介绍了mysqldump加-w参数备份数据时需要注意的事项,需要的朋友可以参考下
    2014-06-06
  • MySQL生成连续的数字/字符/时间序列的方法

    MySQL生成连续的数字/字符/时间序列的方法

    有时候为了生成测试数据,或者填充查询结果中的数据间隔,需要使用到一个连续的数据序列值,所以,今天我们就来介绍一下如何在 MySQL 中生成连续的数字、字符以及时间序列值,需要的朋友可以参考下
    2024-04-04
  • MySQL count(*)统计总数问题汇总

    MySQL count(*)统计总数问题汇总

    在日常开发工作中,我经常会遇到需要统计总数的场景,比如:统计订单总数、统计用户总数等,这篇文章主要介绍了MySQL count(*)统计总数的问题解析,需要的朋友可以参考下
    2022-09-09
  • SQL基础的查询语句

    SQL基础的查询语句

    这篇文章主要给大家分享的是SQL基础的查询语句,SQL语句中,查询是使用最多的操作,SQL不仅能够查询表中的数据,还可以返回算术运算、表达式的结果等,接下来就一起了解一下基本的查询语句,需要的朋友可以参考一下
    2021-11-11
  • navicat 8 for mysql建库的方法

    navicat 8 for mysql建库的方法

    在本篇文章里小编给大家分享的是关于navicat 8 for mysql建库的方法以及相关知识点,需要的朋友们参考学习下。
    2019-08-08
  • SQL中日期与字符串互相转换操作实例

    SQL中日期与字符串互相转换操作实例

    我们经常出于某种目的需要使用各种各样的日期格式,当然我们可以使用字符串操作来构造各种日期格式,下面这篇文章主要给大家介绍了关于SQL中日期与字符串互相转换操作的相关资料,需要的朋友可以参考下
    2022-10-10
  • Navicat连接远程服务器里docker中mysql的方法(已解决)

    Navicat连接远程服务器里docker中mysql的方法(已解决)

    相信大家都有在远程服务器上进行开发吧,其中MySQL的使用率应该也会挺高,这篇文章主要给大家介绍了关于Navicat连接远程服务器里docker中mysql的相关资料,需要的朋友可以参考下
    2024-04-04
  • 在 CentOS 7 下如何使用 Ansible Playbook 实现 MySQL 8.0.34 的二进制安装

    在 CentOS 7 下如何使用 Ansible Playbook 实现 MySQL 8.0.34 的

    要在 CentOS 7 下使用 Ansible Playbook 实现 MySQL 8.0.34 的二进制安装,需要先下载 MySQL 8.0.34 的二进制包,并将其上传至目标服务器,对MySQL 8.0.34 二进制安装过程感兴趣的朋友跟随小编一起看看吧
    2024-03-03
  • mysql数据库的内外连接

    mysql数据库的内外连接

    这篇文章主要介绍了mysql数据库的内外连接,内连接实际上就是利用where子句对两种表形成的笛卡儿积进行筛选,我们前面学习的查询都是内连接,也是在开发过程中使用的最多的连接查询,需要的朋友可以参考下
    2023-07-07
  • mysql一对多关联查询分页错误问题的解决方法

    mysql一对多关联查询分页错误问题的解决方法

    这篇文章主要介绍了mysql一对多关联查询分页错误问题的解决方法,非常不错,具有一定的参考借鉴价值,需要的朋友可以参考下
    2018-09-09

最新评论