mysql用com_MySQL 使用教程
關(guān)于 MySQL
MySQL 是最流行的開源數(shù)據(jù)庫。
本文簡明的講解了 MySQL 如何下載安裝到使用的整個(gè)過程。
MySQL 支持多種特性:
使用 C和 C++編寫,并使用了多種編譯器進(jìn)行測(cè)試,保證了源代碼的可移植性。
支持 AIX、FreeBSD、HP-UX、Linux、Mac OS、NovellNetware、OpenBSD、OS/2 Wrap、Solaris、Windows等多種操作系統(tǒng)。
為多種編程語言提供了 API。這些編程語言包括 C、C++、Python、Java、Perl、PHP、Eiffel、Ruby,.NET和 Tcl 等。支持多線程,充分利用 CPU 資源。
優(yōu)化的 SQL查詢算法,有效地提高查詢速度。
既能夠作為一個(gè)單獨(dú)的應(yīng)用程序應(yīng)用在客戶端服務(wù)器網(wǎng)絡(luò)環(huán)境中,也能夠作為一個(gè)庫而嵌入到其他的軟件中。
提供多語言支持,常見的編碼如中文的 GB 2312、BIG5,日文的 Shift_JIS等都可以用作數(shù)據(jù)表名和數(shù)據(jù)列名。
提供 TCP/IP、ODBC 和 JDBC等多種數(shù)據(jù)庫連接途徑。
提供用于管理、檢查、優(yōu)化數(shù)據(jù)庫操作的管理工具。
支持大型的數(shù)據(jù)庫。可以處理擁有上千萬條記錄的大型數(shù)據(jù)庫。
支持多種存儲(chǔ)引擎。
MySQL 是開源的,所以你不需要支付額外的費(fèi)用。
MySQL 使用標(biāo)準(zhǔn)的 SQL數(shù)據(jù)語言形式。
MySQL 對(duì) PHP 有很好的支持,PHP是目前最流行的 Web 開發(fā)語言。
MySQL是可以定制的,采用了 GPL協(xié)議,你可以修改源碼來開發(fā)自己的 MySQL 系統(tǒng)。
在線 DDL/更改功能,數(shù)據(jù)架構(gòu)支持動(dòng)態(tài)應(yīng)用程序和開發(fā)人員靈活性(5.6[3] 新增)
復(fù)制全局事務(wù)標(biāo)識(shí),可支持自我修復(fù)式集群(5.6[3] 新增)
復(fù)制無崩潰從機(jī),可提高可用性(5.6[3] 新增)
復(fù)制多線程從機(jī),可提高性能(5.6[3] 新增)
下載、安裝
本例用的是 MySQL Community Edition (GPL) 版本,開源免費(fèi)。
版本號(hào):MySQL Community Server 5.6.24
平臺(tái)類型: Windows
安裝方式,可以選擇 MySQL Installer MSI 或者是 編譯壓縮包(形如 mysql-5.6.26-win32.zip 或 mysql-5.6.26-winx64.zip)。
下載完成后,解壓到放到任意目錄,本例為 C:\mysql 目錄
設(shè)置環(huán)境變量
放到 Path 變量下增加 ,C:\mysql\bin
配置
復(fù)制安裝目錄下的 my-default.ini 并重命名為 my.ini ,修改為
[mysqld]
basedir=C:/mysql
datadir=D:/MysqlData/data
basedir 為 mysql 安裝目錄。datadir 為數(shù)據(jù)存放目錄
安裝服務(wù)
安裝作為 Windows 服務(wù)。
MySQL 會(huì)隨著 Windows 的啟動(dòng)和關(guān)閉而啟動(dòng)和關(guān)閉
mysqld –install
C:\Users\Administrator.USER-20150424OX>mysqld –install
Service successfully installed.
其他可選的有:設(shè)置為手動(dòng)啟動(dòng)或者關(guān)閉服務(wù)
mysqld –install-manual
移除服務(wù)
mysqld –remove
啟動(dòng)、關(guān)閉服務(wù)
啟動(dòng)
NET START MySQL
C:\Users\Administrator.USER-20150424OX>NET START MySQL
MySQL 服務(wù)正在啟動(dòng) .
MySQL 服務(wù)已經(jīng)啟動(dòng)成功。
關(guān)閉
NET STOP MySQL
C:\Users\Administrator.USER-20150424OX>NET STOP MySQL
MySQL 服務(wù)正在停止.
MySQL 服務(wù)已成功停止。
測(cè)試安裝是否成功
mysqlshow
C:\Users\Administrator.USER-20150424OX>mysqlshow
+--------------------+
| Databases |
+--------------------+
| information_schema |
| test |
+--------------------+
mysqlshow -u root mysql
C:\Users\Administrator.USER-20150424OX>mysqlshow -u root mysql
Database: mysql
+---------------------------+
| Tables |
+---------------------------+
| columns_priv |
| db |
| event |
| func |
| general_log |
| help_category |
| help_keyword |
| help_relation |
| help_topic |
| innodb_index_stats |
| innodb_table_stats |
| ndb_binlog_index |
| plugin |
| proc |
| procs_priv |
| proxies_priv |
| servers |
| slave_master_info |
| slave_relay_log_info |
| slave_worker_info |
| slow_log |
| tables_priv |
| time_zone |
| time_zone_leap_second |
| time_zone_name |
| time_zone_transition |
| time_zone_transition_type |
| user |
+---------------------------+
mysqladmin version status proc
C:\Users\Administrator.USER-20150424OX>mysqladmin version status proc
mysqladmin Ver 8.42 Distrib 5.6.24, for Win64 on x86_64
Copyright (c) 2000, 2015, 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.
Server version 5.6.24
Protocol version 10
Connection localhost via TCP/IP
TCP port 3306
Uptime: 9 min 12 sec
Threads: 1 Questions: 7 Slow queries: 0 Opens: 67 Flush tables: 1 Open tabl
es: 60 Queries per second avg: 0.012
Uptime: 552 Threads: 1 Questions: 8 Slow queries: 0 Opens: 67 Flush tables:
1 Open tables: 60 Queries per second avg: 0.014
mysqladmin: process list failed; error: ‘Access denied; you need (at least one o
f) the PROCESS privilege(s) for this operation‘
mysql test
C:\Users\Administrator.USER-20150424OX>mysql test
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.6.24 MySQL Community Server (GPL)
Copyright (c) 2000, 2015, 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 –help
連接到服務(wù)器,其中 host 是服務(wù)器IP, user 是用戶名
mysql -h host -u user -p
如果服務(wù)器在本地 ,
mysql -u user –p
提示輸入密碼,驗(yàn)證通過后,如下
C:\Users\Administrator.USER-20150424OX>mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.6.24 MySQL Community Server (GPL)
Copyright (c) 2000, 2015, 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>
斷開與服務(wù)器的鏈接
QUIT
mysql> QUIT
Bye
查詢(命令語句是不區(qū)分大小寫)
mysql> SELECT VERSION(), CURRENT_DATE;
+-----------+--------------+
| VERSION() | CURRENT_DATE |
+-----------+--------------+
| 5.6.24 | 2015-05-10 |
+-----------+--------------+
1 row in set (0.01 sec)
列出所有數(shù)據(jù)庫
mysql> SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)
創(chuàng)建一個(gè)自己的數(shù)據(jù)庫 menagerie
mysql> CREATE DATABASE menagerie;
Query OK, 1 row affected (0.03 sec)
給自己授予管理員權(quán)限
GRANT ALL ON menagerie.* TO ‘your_mysql_name‘@‘your_client_host‘;
訪問數(shù)據(jù)庫 menagerie
mysql> USE menagerie
Database changed
列出數(shù)據(jù)庫表
mysql> SHOW TABLES;
Empty set (0.00 sec)
創(chuàng)建表 pet
mysql> CREATE TABLE pet (name VARCHAR(20), owner VARCHAR(20),
-> species VARCHAR(20), sex CHAR(1), birth DATE, death DATE);
Query OK, 0 rows affected (0.43 sec)
查看 pet 表的詳情
mysql> DESCRIBE pet;
+---------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+-------+
| name | varchar(20) | YES | | NULL | |
| owner | varchar(20) | YES | | NULL | |
| species | varchar(20) | YES | | NULL | |
| sex | char(1) | YES | | NULL | |
| birth | date | YES | | NULL | |
| death | date | YES | | NULL | |
+---------+-------------+------+-----+---------+-------+
6 rows in set (0.01 sec)
插入數(shù)據(jù)
mysql> INSERT INTO pet
-> VALUES (‘Puffball‘,‘Diane‘,‘hamster‘,‘f‘,‘1999-03-30‘,NULL);
Query OK, 1 row affected (0.04 sec)
查詢所有的數(shù)據(jù)
mysql> SELECT * FROM pet;
+----------+-------+---------+------+------------+-------+
| name | owner | species | sex | birth | death |
+----------+-------+---------+------+------------+-------+
| Puffball | Diane | hamster | f | 1999-03-30 | NULL |
+----------+-------+---------+------+------------+-------+
1 row in set (0.00 sec)
修改數(shù)據(jù)
mysql> UPDATE pet SET birth = ‘1989-08-31‘ WHERE name = ‘Puffball‘;
Query OK, 1 row affected (0.11 sec)
Rows matched: 1 Changed: 1 Warnings: 0
刪除數(shù)據(jù)
mysql> DELETE FROM pet;
Query OK, 1 row affected (0.04 sec)
參考
原文:http://my.oschina.net/waylau/blog/413904
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎(jiǎng)勵(lì)來咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎(jiǎng)總結(jié)
以上是生活随笔為你收集整理的mysql用com_MySQL 使用教程的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: mac 连接hbase的图形化界面_MA
- 下一篇: 拼多多商家版怎么上架商品