| 订阅 | 在线投稿
分享
 
 
 

如何在Unix系统环境下安装MySQL数据库

来源:互联网  宽屏版  评论
2008-07-01 06:56:50

本文为【如何在Unix系统环境下安装MySQL数据库】的汉字拼音对照版显示拼音

anzhuangshijianyiniweiMySQLguanlichuangjianyigeyonghuhezuyougaizuyonghuyunxingmysqlfuwuqibingzhixingguanlirenwuyekeyiyirootshenfenyunxingfuwuqidanshibutuijian

diyibuchuangjianyigeyonghulaiyunxingfuwuqizaiSolarisheunixxiakeyiyonguseraddhegroupadd使shiyonggongjulaiwanchengquyigemingzijiaomysqlbadangranrenhenixihuandeiddoukeyisuoyizaizuoqitashiqingzhiqianliyongsuminglingchengweiroot

$ su - root

$ groupadd mysql

$ useradd -g mysql mysql

xuanzeyaoanzhuangmysqlruanjiandeweizhibingjiangdangqianmuluzhuanhuandaogaimuluyibandejianganzhuangdao/usr/local,zheshiMySQLruanjiandebiaozhunanzhuangweizhixianzaijinqu

$ cd /usr/local

jiekairuanjianbao

$ gunzip -c /tmp/mysql -3.23.xx.tar.gz | tar -xf -

yinweiyaoanzhuangzaiSolarisfuwuqishangsuoyiruguoanzhuangdeshibutongbanbendetarliruGNUdetarzeshangmiandeminglingjiangbuhuiqizuoyongzheshiyaoyongxiamiandemingling

$ gunzip -c /tmp/mysql -3.23.xx.tar.gz | gtar -xf -

xianzaikeyichakanyixiaxinmulukanshifoucunzai

$ ls -ld mysql*

total 1

drwxr-xr-x 28 user user 1024 Jul 18 14:29 mysql-3.23.x/

xiayibushichuangjianyigefuhaolianjieyi便biananzhuangnenggouzhixiang/usr/local/mysql:

$ ln -s mysql-3.23.x mysql

$ ls -ld mysql*

jiuhuichuxianbiaoshilianjiechenggongdexinglaianzhaoshangtieruanjiananzhuanghaohouhuanyoujixiangpeizhirenwuyaowanchengyunxingscripts/mysql_install_dbchuangjianMySQLxukebiao

$ scripts/mysql_install_db

Preparing db talbe

Preparing host table

Preparing user table

Preparing func table

Preparing tables_priv table

Preparing columns_priv table

Installing all prepared tables

010726 19:40:05 ./bin/mysqld: Shutdown Complete

shezhierjinzhiwenjiandesuoyouquanconger使shizhiguirootsuoyoubingshuyuqianmianchuangjiandeMySQL

guanliyuanzuzhegeliziweimysql

$ chown -R root /usr/local/mysql

$ chgrp -R mysql /usr/local/mysql

jiangshujumuludesuoyouquanshezhiweixianqianchuangjiandeMySQLguanliyonghu

$ chown -R mysql /usr/local/mysql/data

suoyouquanshezhiwancheng

qidongfuwuqixuyunxingsafe_mysqld:

$ bin/safe_mysqld --usr=mysql &

yibanyaorangMySQLzaifuwuqiyindaoshijiuyunxingweicikeyijiangsupport-files/mysql.serverfuzhidaoxitongshidangdeweizhijiuokle

weilequebaoMySQLnengzhengchanggongzuoxuyaoyunxingyixiejiandandeceshi. ruguoshuchujieguo: BINDIR = /usr/local/mysql/binjiuzhengmingMySQLgongzuozhengchang. BINDIR dezhiyushangmianxuanzedeprefix xuanxiangyouguan

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

# BINDIR/mysqlshow -p

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

| Databases |

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

| mysql |

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

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

yidannianzhuangleMySQL, tajianghuizidongshengchenglianggeshujukuyigeyongyuguanliyonghuzhujihefuwuqishujukuquanxianlingyigeshiceshishujukutest databasewomenkeyi使shiyongceshishujuku danshiwomenxiangjiandankuaijiedexiangnijieshaoMySQLzhongyixieke使shiyongdezhilingdegaimaozhehuankeyiquebao root beishezhiweinenggouwanquan访fangwenfuwuqiliru: rootkeyiyuanxuchuangjianshujukubiaodandeng.. suoyiwomenjiangchuangjianyigetest2shujukuyongyuyihoudeceshizaitongguozhilingjinruMySQLqianxitongjiangtishishuruxinchuangjianderootkouling yinggaijideniyigaiguo rootdekoulingle

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

# mysql -u root -p

mysql> show databases;

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

| Database |

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

| mysql |

| test |

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

mysql> create database test2;

Query OK, 1 row affected (0.00 sec)

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

anzhaoxiamianliangduandaimaxuanze使shiyongxindeshujukubingchuangjianyigemingchengweitst_tbldebiao tayoulianggeziduandiyigeziduanfield 1weiid ziduantongguotakeyikandaojiludeidhaocongbenzhishangkanzhezhishiyiliechunshuzidiergeziduanweimingchengziduanzaiqizhongkeyicunchushudemingchengzhexieziduandegeshiwei field 1 (id) weichangduwei3dezhengshuxing(int) field 2 (name)weichangduwei50dezifuchuanxing(char) womenduiiddefuzhikeyiduishujuchazhaohebiaoyin

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

mysql> use test2;

Database changed

mysql> CREATE TABLE books ( id int(3) not null

-> auto_increment, name char(50) not null,

-> unique(id), primary key(id));

Query OK, 0 rows affected (0.00 sec)

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

xianzaiyongxiamianminglingjianchakushifouzhengque

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

mysql> show tables;

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

| Tables in test2 |

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

| books |

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

1 row in set (0.00 sec)

mysql> describe books;

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

| Field | Type | Null | Key | Default | Extra |

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

| id | int(3) | | PRI | 0 | auto_increment |

| name | char(50) | |

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

2 rows in set (0.00 sec)

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

zhuyidescribezhilingjibenmiaohuichubiaodebuju

OK, xiamianjieshaoyixiezhenzhengyouyongdeSQLzhilingruhezaishujukuzhongcharuhexuanzeshujuxianzaikeyixiangxinjianbiaozhongjiarujitiaojilu

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

mysql> INSERT INTO books (name) values(PHP 4 Newbies);

Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO books (name) values(Red Hat Linux 6 Server);

Query OK, 1 row affected (0.00 sec)

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

xianzaijianchayixiaxindejilubingshuxiyixiaselectzhiling

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

mysql> SELECT * from books;

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

| id | name |

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

| 1 | PHP for Newbies |

| 2 | Red Hat Linux 6 Server |

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

2 rows in set (0.00 sec)

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

zheyangMySQLfuwuqidejiuyijingnengzhengchangyunxinglewomenkeyijixuzengjiajiludanshizaicijiumeiyougengduoyiyile

zhuyidangnixiangshujukucharujilushibubizhidingidzheshiyinweinichuangjianid ziduanyouzidongzengjiadexuanxiang

xiamianjieshaoruhejinxingkuaisushanchuzhezhishigeiniyigejiandanxinxijizhunikeyizaimysql webzhandianhttp://www.mysql.comzhaodaosuoyounisuoxiangyaodemysqlzhilinghefuwuqidexinxi

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

mysql> delete from books where id=1;

Query OK, 1 row affected (0.00 sec)

mysql> select * from books;

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

| id | name |

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

| 2 | Red Hat Linux 6 Server |

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

1 row in set (0.00 sec)

原文
安装时建议你为MySQL管理创建一个用户和组。由该组用户运行mysql服务器并执行管理任务。(也可以以root身份运行服务器,但是不推荐) 第一步创建一个用户来运行服务器。在Solaris和unix下,可以用useradd和groupadd使用工具来完成。取一个名字叫mysql吧。(当然,任何你喜欢的id都可以)所以在做其它事情之前,利用su命令成为root: $ su - root $ groupadd mysql $ useradd -g mysql mysql 选择要安装mysql软件的位置,并将当前目录转换到该目录。一般的,将安装到/usr/local,这是MySQL软件的标准安装位置。现在进去, $ cd /usr/local 解开软件包: $ gunzip -c /tmp/mysql -3.23.xx.tar.gz | tar -xf - 因为要安装在Solaris服务器上,所以如果安装的是不同版本的tar,例如GNU的tar,则上面的命令将不会起作用。这是要用下面的命令: $ gunzip -c /tmp/mysql -3.23.xx.tar.gz | gtar -xf - 现在可以查看一下新目录,看是否存在 $ ls -ld mysql* total 1 drwxr-xr-x 28 user user 1024 Jul 18 14:29 mysql-3.23.x/ 下一步是创建一个符号链接,以便安装能够指向/usr/local/mysql: $ ln -s mysql-3.23.x mysql $ ls -ld mysql* 就会出现表示连接成功的行来。按照上帖软件安装好后,还有几项配置任务要完成。运行scripts/mysql_install_db创建MySQL许可表: $ scripts/mysql_install_db Preparing db talbe Preparing host table Preparing user table Preparing func table Preparing tables_priv table Preparing columns_priv table Installing all prepared tables 010726 19:40:05 ./bin/mysqld: Shutdown Complete 设置二进制文件的所有权,从而使之归root所有,并属于前面创建的MySQL 管理员组(这个例子为mysql) $ chown -R root /usr/local/mysql $ chgrp -R mysql /usr/local/mysql 将数据目录的所有权设置为先前创建的MySQL管理用户 $ chown -R mysql /usr/local/mysql/data 所有权设置完成 启动服务器需运行safe_mysqld: $ bin/safe_mysqld --usr=mysql & 一般要让MySQL在服务器引导时就运行。为此,可以将support-files/mysql.server复制到系统适当的位置就ok了。 为了确保MySQL能正常工作,需要运行一些简单的测试. 如果输出结果: BINDIR = /usr/local/mysql/bin,就证明MySQL工作正常. BINDIR 的值与上面选择的prefix 选项有关。 -------------------------------------------------------------------------------- # BINDIR/mysqlshow -p +---------------+ | Databases | +---------------+ | mysql | +---------------+ -------------------------------------------------------------------------------- 一旦你安装了MySQL, 它将会自动生成两个数据库。一个用于管理用户、主机和服务器数据库权限。另一个是测试数据库(test database)。我们可以使用测试数据库。 但是,我们想简单快捷的向你介绍MySQL中一些可使用的指令的概貌。这还可以确保 root 被设置为能够完全访问服务器,例如: root可以允许创建数据库、表单等.. 所以我们将创建一个test2数据库用于以后的测试。在通过指令进入MySQL前,系统将提示输入新创建的root口令。 应该记得你已改过 root的口令了。 -------------------------------------------------------------------------------- # mysql -u root -p mysql> show databases; +----------------+ | Database | +----------------+ | mysql | | test | +----------------+ mysql> create database test2; Query OK, 1 row affected (0.00 sec) -------------------------------------------------------------------------------- 按照下面两段代码,选择使用新的数据库,并创建一个名称为tst_tbl的表, 它有两个字段。第一个字段(field 1)为id 字段,通过它可以看到记录的id号。从本质上看,这只是一列纯数字。第二个字段为名称字段,在其中可以存储书的名称。这些字段的格式为: field 1 (id) 为长度为3的整数型(int), field 2 (name)为长度为50的字符串型(char)。 我们对id的赋值可以对数据查找和标引。 -------------------------------------------------------------------------------- mysql> use test2; Database changed mysql> CREATE TABLE books ( id int(3) not null -> auto_increment, name char(50) not null, -> unique(id), primary key(id)); Query OK, 0 rows affected (0.00 sec) -------------------------------------------------------------------------------- 现在用下面命令检查库是否正确。 -------------------------------------------------------------------------------- mysql> show tables; +---------------------+ | Tables in test2 | +---------------------+ | books | +---------------------+ 1 row in set (0.00 sec) mysql> describe books; +-------+-------------+------+------+----------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------+-------------+------+------+----------+----------------+ | id | int(3) | | PRI | 0 | auto_increment | | name | char(50) | | +-------+-------------+------+------+----------+----------------+ 2 rows in set (0.00 sec) -------------------------------------------------------------------------------- 注意:describe指令基本描绘出表的布局。 OK, 下面介绍一些真正有用的SQL指令:如何在数据库中插入和选择数据。现在可以向新建表中加入几条记录。 -------------------------------------------------------------------------------- mysql> INSERT INTO books (name) values(PHP 4 Newbies); Query OK, 1 row affected (0.00 sec) mysql> INSERT INTO books (name) values(Red Hat Linux 6 Server); Query OK, 1 row affected (0.00 sec) -------------------------------------------------------------------------------- 现在检查一下新的记录,并熟悉一下select指令。 ------------------------------------------------------------------------------- mysql> SELECT * from books; +----+----------------------------------+ | id | name | +----+----------------------------------+ | 1 | PHP for Newbies | | 2 | Red Hat Linux 6 Server | +----+----------------------------------+ 2 rows in set (0.00 sec) -------------------------------------------------------------------------------- 这样MySQL服务器的就已经能正常运行了。我们可以继续增加记录,但是在此就没有更多意义了。 注意:当你向数据库插入记录时,不必指定id。这是因为你创建id 字段有自动增加的选项。 下面介绍如何进行快速删除。这只是给你一个简单信息,记住你可以在mysql web站点http://www.mysql.com找到所有你所想要的mysql指令和服务器的信息。 -------------------------------------------------------------------------------- mysql> delete from books where id=1; Query OK, 1 row affected (0.00 sec) mysql> select * from books; +----+-----------------------------------+ | id | name | +----+-----------------------------------+ | 2 | Red Hat Linux 6 Server | +----+-----------------------------------+ 1 row in set (0.00 sec)
󰈣󰈤
 
 
 
>>返回首页<<
 
 热帖排行
 
 
王朝网络微信公众号
微信扫码关注本站公众号wangchaonetcn
 
 
静静地坐在废墟上,四周的荒凉一望无际,忽然觉得,凄凉也很美
©2005- 王朝网络 版权所有