1. 程式人生 > >Ubuntu系統下的Mysql安裝與使用

Ubuntu系統下的Mysql安裝與使用

1=1 能夠 query val webpage mat init 字段 use

摘要

在本篇博文中。筆者將從基礎出發。介紹Mysql在Linux環境下的安裝和基本使用命令,僅適用於Mysql剛開始學習的人。大牛請繞道……


安裝Mysql數據庫

這裏介紹最最簡單的安裝方式,至於編譯安裝,能夠下載安裝包, ./configure 生成Makefile。然後 make clean, make , make test, make install 我想這些命令應該非常基本了吧,這裏不再敖述。

1. 安裝命令

[email protected]:~$ sudo apt-get install mysql-server mysql-client


2. 查看數據庫版本號,這裏password為“11”

[email protected]:~$ sudo mysqladmin -u root -p version
Enter password: 
mysqladmin  Ver 8.42 Distrib 5.1.70, for debian-linux-gnu on i486
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

3. 查看Mysql服務狀態。啟動或者關閉Mysql服務

[email protected]:~$ service mysql status
mysql start/running, process 899

[email protected]
/* */:~$ sudo /etc/init.d/mysql start|stop|restart

4. 登陸數據庫。並退出操作

命令裏的 -u 指的是username, 這裏指的是 root, -p 後接password, 這裏指安裝數據庫時候設置的password,筆者的為11

[email protected]:~$ sudo mysql -uroot -p11

5. 數據庫內的基本操作

//  顯示數據庫
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| jxc                |
| mysql              |
+--------------------+
3 rows in set (0.08 sec)

// 使用某個數據庫
mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed

// 創建數據庫
mysql> create database thinkphp;
Query OK, 1 row affected (0.00 sec)

// 刪除數據庫
mysql> drop database thinkphp;
Query OK, 0 rows affected (0.07 sec)

// 顯示數據庫中的某張表
mysql> show tables;

// 顯示某個表的結構
mysql> describe slow_log;

// 選擇顯示的表內容
mysql> select * from slow_log;
Empty set (0.00 sec)

// 刪除表
mysql> drop table slow_log;

// 導入數據庫
mysql> source /var/www/webPage.sql;
或者命令: ~$ sudo mysql –uroot –p11 thinktest < WebPage.sql

mysql 表結構CRUD操作

加入表字段
   alter table tablename add elemName varchar(10) not null;
改動某個表字段類型
   alter table tablename change elemName elemNewName varchar(10) null;
   alter table tablename modify elemName varchar(10) null;
刪除某個字段
   alter table tablename drop elemName;

向數據表中插入數據
   insert into tablename (elem1,elem2,...) values (A,B,...);

刪除數據表中數據
   delete from tablename where id>1 order by time limit 1;

更新數據表中數據
   UPDATE tablename SET elem1=1, elem2=2 WHERE id=1; 



??

Ubuntu系統下的Mysql安裝與使用