Chinaunix首页 | 论坛 | 博客
  • 博客访问: 784132
  • 博文数量: 231
  • 博客积分: 3217
  • 博客等级: 中校
  • 技术积分: 2053
  • 用 户 组: 普通用户
  • 注册时间: 2011-07-04 12:01
文章分类

全部博文(231)

文章存档

2015年(1)

2013年(10)

2012年(92)

2011年(128)

分类:

2011-09-15 08:31:43

原文地址:mysql 简单入门级使用命令 作者:ykyx00




检查mysql是否安装
# rpm -qa |grep mysql
mysql-libs-5.1.47-4.el6.x86_64
安装mysql-server
# yum -y install mysql mysql-server 
启动mysql server 服务,并设置为开机启动
# /etc/init.d/mysqld start
# chkconfig mysqld on
为了数据库安装,执行初始化设置
# mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!


In order to log into MySQL to secure it, we'll need the current
password for the root user.  If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):      //此处无密码可以直接enter,有密码需要输入
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.

Set root password? [Y/n] y                //此root密码为mysql的root密码,非本地root密码
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y      //移除匿名可以登录用户
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] y          //不允许root远程登录
 ... Success!

By default, MySQL comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] y      //移除测试数据库(匿名)
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y          //重新reload 权限表
 ... Success!

Cleaning up...



All done!  If you've completed all of the above steps, your MySQL
installation should now be secure.

Thanks for using MySQL!

以root 登录进入mysql管理台
# mysql -uroot -p
Enter password:                   //输入密码

mysql> show databases ;       //查看列出数据库
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
+--------------------+
2 rows in set (0.01 sec)

mysql> create database test;    //创建名为test的数据库
Query OK, 1 row affected (0.00 sec)

mysql> show databases;          //再次查看数据库,可以看到我们新加的数据库 test
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| test               |
+--------------------+
3 rows in set (0.00 sec)
mysql> use test                   //进入数据库test
Database changed
mysql> show tables;             //查看数据库中的表
Empty set (0.01 sec)

mysql>create table mail(             //创建mail表,定义三个值 id、username,password
id varchar(25) not null, 
username varchar(30) not null, 
password varchar(50) not null);
Query OK, 0 rows affected (0.22 sec)

mysql> show tables ;           //查看数据表,可以看到已经有mail表了
+----------------+
| Tables_in_test |
+----------------+
| mail           |
+----------------+
1 row in set (0.00 sec)

mysql> desc mail ;                        //查看数据表结构
+----------+-------------+------+-----+---------+-------+
| Field    | Type        | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+-------+
| id       | varchar(25) | NO   |     | NULL    |       |
| username | varchar(30) | NO   |     | NULL    |       |
| password | varchar(50) | NO   |     | NULL    |       |
+----------+-------------+------+-----+---------+-------+
3 rows in set (0.01 sec)


mysql> select * from mail ;          //查看数据表里的内容,目前为空
Empty set (0.00 sec)

mysql> insert into mail values ('001','jack','123456') ;     //插入一条记录到mail表
Query OK, 1 row affected (0.00 sec)

mysql> insert into mail values ('002','frank','123456') ;
Query OK, 1 row affected (0.00 sec)

mysql> select * from mail ;               //再次查询可以看到表里的内容
+-----+----------+----------+
| id  | username | password |
+-----+----------+----------+
| 001 | jack     | 123456   |
| 002 | frank    | 123456   |
+-----+----------+----------+
2 rows in set (0.00 sec)

mysql> update mail set password=111 where username='frank';          //更新一条表的内容
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> select * from mail ;                
+-----+----------+----------+
| id  | username | password |
+-----+----------+----------+
| 001 | jack     | 123456   |
| 002 | frank    | 111      |
+-----+----------+----------+
2 rows in set (0.00 sec)


mysql> delete from mail where username='jack';                  //删除表里username=jack的内容
Query OK, 1 row affected (0.00 sec)

mysql> select * from mail ;
+-----+----------+----------+
| id  | username | password |
+-----+----------+----------+
| 002 | frank    | 111      |
+-----+----------+----------+
1 row in set (0.00 sec)

mysql> delete from mail ;                                      //删除mail表里所有的内容
Query OK, 1 row affected (0.00 sec)

mysql> select * from mail ;
Empty set (0.00 sec)

mysql> drop table mail ;                                    //删除数据表mail
Query OK, 0 rows affected (0.00 sec)

mysql> drop database test ;                              //删除数据库test
Query OK, 0 rows affected (0.00 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
+--------------------+
2 rows in set (0.00 sec)

mysql> grant select,update on *.*  to user1@192.168.0.118 identified by '123' ;       //授权给user1可以在192.168.0.118 的所有数据库的所有表里进行查询和更新的功能,密码为‘123’
Query OK, 0 rows affected (0.00 sec)

阅读(1220) | 评论(0) | 转发(0) |
0

上一篇:共享内存

下一篇:html语言学习

给主人留下些什么吧!~~