mysql基本操作

来源:互联网 发布:linux 打印机 编辑:程序博客网 时间:2024/06/06 15:06

启动服务
打开cmd命令行(有时候在cmd下输入mysqld无法启动服务,就自己进到bin目录下,双击这个exe吧):
D:\Program Files\MySQL Server 5.5\bin>mysqld
D:\Program Files\MySQL Server 5.5\bin>mysql -uroot -proot  (我的用户名密码都是root)
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.23 MySQL Community Server (GPL)
Copyright (c) 2000, 2011, 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>
连接mysql
cmd
cd  C:\Program Files\MySQL\MySQL Server 5.5\bin
mysql -hlocalhost -uroot -proot   连接localhost下  root/root用户就会进入  mysql>
mysql>
修改密码
cmd:
D:\Program Files\MySQL Server 5.5\bin>mysqladmin -u root -p  password
Enter password:
New password: ********
Confirm new password: ********
输入root的空密码,即按回车,然后输入新的密码即可。
新建用户
新建一个名为test的用户,只允许在本机登录,拥有查、插、改、删的权限,密码为password:
mysql> grant select,insert,update,delete on mydb.* to identified by "password";
Query OK, 0 rows affected (0.00 sec)
显示数据列表
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)
使用mysql数据库
mysql> use mysql;
Database changed
显示数据库下所有表
mysql> show tables;
+---------------------------+
| Tables_in_mysql           |
+---------------------------+
| columns_priv              |
| db                        |
| event                     |

……省略……

| user                      |
+---------------------------+
24 rows in set (0.00 sec)
显示表的结构
mysql> describe db;
+-----------------------+---------------+------+-----+---------+-------+
| Field                 | Type          | Null | Key | Default | Extra |
+-----------------------+---------------+------+-----+---------+-------+
| Host                  | char(60)      | NO   | PRI |         |       |
……省略……
+-----------------------+---------------+------+-----+---------+-------+
22 rows in set (0.00 sec)
建库
create database 数据库名;
建表
use 数据库名;
create table 表名 (字段设定列表);
删库和删表
drop database 数据库名;
drop table 表名;
将表中记录清空
delete from 表名;
显示表中的所有记录
select * from 表名;
退出MySQL服务器
MySQL>EXIT 

0 0
原创粉丝点击