Home > Database > Mysql Tutorial > MySQL 的安装和使用

MySQL 的安装和使用

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-07 17:10:43
Original
1180 people have browsed it

MySQL (发音为 My Ess Que Ell)是 Tcx 公司(http://www.tcx.se)开发的一个多人使用、多执行绪的 SQL 资料库 Server。MySQL

MySQL 

一、MySQL的下载

  

二、MySQL 的安装 

  本文所使用的 

  

  取得 

# cd /usr/local 

# tar zxvf mysql-3.22.27.tar.gz 

# cd mysql-3.22.27 

设定 

# ./configure --prefix=/usr/local/mysql \ 

#--with-charset=big5 

  开始编译并安装: 

# make 

# make install 

# scripts/mysql_install_db 

  最后一个步骤是用来产生 

三、启动、停止 MySQL 

  要启动 

# /usr/local/mysql/share/mysql.server start 

  注意在第一次执行前,须将 

  要停止 MySQL 的方法: 

# /usr/local/mysql/bin/mysqladmin shutdown 

  如果你为 

# /usr/local/mysql/bin/mysqladmin -u root -p shutdown 

四、管理与使用 MySQL 简介 

  在你开始前 

mysql 的使用语法如下: 

mysql [-u username] [-h host] [-p[password]] [dbname] 

  

  在你第一次安装好 

  使用 

# /usr/local/mysql/bin/mysql -u root mysql 

Reading table information for completion of table and column names 

You can turn off this feature to get a quicker startup with -A 

Welcome to the MySQL monitor. Commands end with ; or \g. 

Your MySQL connection id is 201 to server version: 3.22.27 

Type 'help' for help. 

mysql> 

  在下了 

mysql> update user set password=password('新密码') where user='root'; 

Query OK, 0 rows affected (0.00 sec) 

Rows matched: 2 Changed: 0 Warnings: 0 

mysql> FLUSH PRIVILEGES; 

Query OK, 0 rows affected (0.00 sec) 

mysql> quit 

Bye 

  注意每个指令后要加上一个分号 

在更新 

mysql -u root -p新密码 

或者是这样,,让 

mysql -u root -p

  (2)资料库维护 

  接下来,我们以简单的通讯录资料库作为例子,来介绍如何用 mysql 工具程序来做资料库的维护(新增、授权、资料表维护等)。 

  首先,以 

# /usr/local/mysql/bin/mysql -u root -p 

Enter password: 

Welcome to the MySQL monitor. Commands end with ; or \g. 

Your MySQL connection id is 207 to server version: 3.22.27 

Type 'help' for help. 

mysql> create databae addbook; 

Query OK, 1 row affected (0.00 sec) 

指定使用 

mysql> use addbook; 

Database changed 

mysql> create table friends ( 

  -> name Char(15), 

  -> telphone VarChar(20), 

  -> icq Char(10), 

  -> address VarChar(30) 

  -> ); 

Query OK, 0 rows affected (0.00 sec) 

  新增几笔资料,并查询看看: 

mysql> insert into friends values( 

  

  -> ); 

Query OK, 1 row affected (0.00 sec) 

mysql> insert into friends (name, icq, telphone, address ) Values ( 

  

  -> ); 

Query OK, 1 row affected (0.01 sec) 

mysql> select * from friends; 

+-------+----------+----------+--------------+ 

| name | telphone | icq | address | 

+-------+----------+----------+--------------+ 

| maa | 29016710 | 46243046 | 台北县新庄市 

| cxlin | 7654321 | 39425893 | 台北县 

+-------+----------+----------+--------------+ 

2 rows in set (0.00 sec) 

  第二个 insert 指令指定了资料栏位的插入顺序,用法较第一个为弹性,而第一个指令必须依资料表建立结构时的顺序插入资料。 

  更新、删除资料表记录: 

mysql> update friends set address = "桃园县" where name = "cxlin"; 

Query OK, 1 row affected (0.00 sec) 

Rows matched: 1 Changed: 1 Warnings: 0 

mysql> select * from friends where name = "cxlin"; 

+-------+----------+----------+---------+ 

| name | telphone | icq | address | 

+-------+----------+----------+---------+ 

| cxlin | 7654321 | 39425893 | 桃园县 

+-------+----------+----------+---------+ 

1 row in set (0.00 sec) 

mysql> delete from friends where name = "maa"; 

Query OK, 1 row affected (0.01 sec) 

mysql> select * from friends; 

+-------+----------+----------+---------+ 

| name | telphone | icq | address | 

+-------+----------+----------+---------+ 

| cxlin | 7654321 | 39425893 | 桃园县 

+-------+----------+----------+---------+ 

1 row in set (0.00 sec) 

最后,建好资料库与资料表后,把 

mysql> grant select, insert, update, delete 

-> on addbook.* 

-> to maa@localhost identified by '1234567'; 

Query OK, 0 rows affected (0.00 sec) 

之后,可用 

# /usr/local/mysql/bin/mysql -u maa -p addbook 

Enter password: 

Reading table information for completion of table and column names 

You can turn off this feature to get a quicker startup with -A 

Welcome to the MySQL monitor. Commands end with ; or \g. 

Your MySQL connection id is 211 to server version: 3.22.27 

Type 'help' for help. 

mysql> status 

-------------- 

./mysql Ver 9.36 Distrib 3.22.27, for pc-linux-gnu (i686) 

Connection id: 26 

Current database: addbook 

Current user: maa@localhost 

Server version 3.22.27 

Protocol version 10 

Connection Localhost via UNIX socket 

UNIX socket /tmp/mysql.sock 

Uptime: 2 hours 29 min 33 sec 

Threads: 11 Questions: 107 Slow queries: 0 Opens: 11 Flush tables: 1 

Open 7 

-------------- 

收回资料库使用权限的方法如下(以 MySQL root 进入): 

mysql> revoke delete on addbook.* from maa@localhost; 

Query OK, 0 rows affected (0.00 sec) 

mysql> revoke all privileges on addbook.* from maa@localhost; 

Query OK, 0 rows affected (0.00 sec) 

第二个指令用来收回全部的权限。 

linux

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template