啓動服務
打開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