網(wǎng)友的材料,初學(xué)者看看吧:-)
1、 安裝和啟動(dòng)
安裝mysql可以通過(guò)freebsd自帶的port來(lái)安裝,在/stand/sysinstall中來(lái)選擇,選擇configure中的 packages.安裝之后,mysql的所有安裝文件都被安裝在了/usr/local中.mysql在第三張盤和第四張盤里面都有。
啟動(dòng)mysql的服務(wù)器
chu888# cd /usr/local/etc/rc.d
chu888# ls
00mysql-client.sh mysql-server.sh
chu888# ./mysql-server.sh start
使用mysql的客戶端
chu888# cd /usr/local/bin
chu888# ls my*
my_print_defaults mysqlaccess
myisamchk mysqladmin
myisamlog mysqlbinlog
myisampack mysqlbug
mysql mysqlcheck
mysql_config mysqld_multi
mysql_convert_table_format mysqldump
mysql_find_rows mysqldumpslow
mysql_fix_privilege_tables mysqlhotcopy
mysql_install_db mysqlimport
mysql_setpermission mysqlshow
mysql_zap mysqltest
chu888# ./mysql
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 2 to server version: 3.23.47
Type ‘help;‘ or ‘h‘ for help. Type ‘c‘ to clear the buffer.
mysql>
如果看到這個(gè)mysql>的提示符,說(shuō)明你以可以使用這個(gè)數(shù)據(jù)庫(kù)了。
2 mysql管理
首先我們應(yīng)該認(rèn)識(shí)以下幾個(gè)應(yīng)用程序:
mysql是一個(gè)交互式的程序,允許將SQL語(yǔ)句發(fā)布到服務(wù)器上并瀏覽其結(jié)果
mysqladmin一個(gè)管理程序,允許執(zhí)行諸如關(guān)閉服務(wù)器以及創(chuàng)建或刪除數(shù)據(jù)庫(kù)的工作
isamchk和myisamchk這些實(shí)用程序?qū)椭阃瓿杀淼姆治龊蛢?yōu)化,以及在表?yè)p壞時(shí)進(jìn)行崩潰恢復(fù)。
Mysqldump一個(gè)工具,用于備份或?qū)?shù)據(jù)庫(kù)拷貝到另一個(gè)服務(wù)器中
3 數(shù)據(jù)庫(kù)目錄的位置
可以使用mysqladmin直接得到
chu888# ./mysqladmin variables
4 mysql數(shù)據(jù)表的表示法
格式文件 .frm 描述表的結(jié)構(gòu)
數(shù)據(jù)文件 .isd或.myd 包含表的數(shù)據(jù)
索引文件 .isd或.myi索引文件
5 關(guān)閉數(shù)據(jù)庫(kù)
chu888#./mysqladmin shutdown
6 備份數(shù)據(jù)庫(kù)
chu888#mysqldump samp_db>/usr/tmp/samp_db.2002
7 恢復(fù)數(shù)據(jù)庫(kù)
chu888#mysqldump samp_db</usr/tmp/samp_db.2002
8 修改數(shù)據(jù)庫(kù)的密碼
chu888# ./mysqladmin -uroot -p password ‘123456‘
chu888# ./mysql -h localhost -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 2 to server version: 3.23.47
Type ‘help;‘ or ‘h‘ for help. Type ‘c‘ to clear the buffer.
mysql>
mysql的最基本使用
chu888# ./mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 6 to server version: 3.23.47
Type ‘help;‘ or ‘h‘ for help. Type ‘c‘ to clear the buffer.
mysql> show databases;
+----------+
| Database |
+----------+
| mysql |
| test |
+----------+
2 rows in set (0.00 sec)
mysql> create database chu888;
Query OK, 1 row affected (0.01 sec)
mysql> use chu888;
Database changed
mysql> select now(),user(),version();
+---------------------+----------------+-----------+
| now() | user() | version() |
+---------------------+----------------+-----------+
| 2003-06-19 06:13:58 | root@localhost | 3.23.47 |
+---------------------+----------------+-----------+
1 row in set (0.00 sec)
mysql>
有得時(shí)候在輸入大量的SQL腳本時(shí)比較麻煩,這時(shí)如何辦哪?
#./mysql<my_file.sql
這種方法就比較好。
mysql> create database testsql;
Query OK, 1 row affected (0.01 sec)
mysql> show databases;
+----------+
| Database |
+----------+
| chu888 |
| mysql |
| test |
| testsql |
+----------+
4 rows in set (0.02 sec)
mysql>
mysql> create table president
-> (
-> last_name varchar(15) not null,
-> first_name varchar(15) not null,
-> suffix varchar(5) null,
-> city varchar(20) not null,
-> state varchar(2) not null,
-> birth date not null,
-> death date null
-> )
-> ;
Query OK, 0 rows affected (0.02 sec)
mysql> insert into president values(‘Robbert‘,‘Wan‘,‘ok‘,‘Ol‘,‘a(chǎn)‘,‘1934-11-22‘,‘1989-2-11‘);
Query OK, 1 row affected (0.02 sec)
mysql> insert into president values(‘a(chǎn)‘,‘Wan‘,‘ok‘,‘Ol‘,‘a(chǎn)‘,‘1934-11-22‘,‘1989-2-11‘);
Query OK, 1 row affected (0.01 sec)
mysql> update president set last_name=‘liu‘ where last_name=‘a(chǎn)‘
-> ;
Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> delete from president where last_name=‘liu‘
-> ;
Query OK, 1 row affected (0.01 sec)
mysql>