MYSQL完全安装使用指南

来源:互联网 发布:js window close 事件 编辑:程序博客网 时间:2024/05/21 06:30

原网址:http://www.chinaunix.net/jh/17/178508.html

完全拷贝,无任何修改!

[精华] (原创)MYSQL完全安装使用指南


http://www.chinaunix.net 作者:cloudxx  发表于:2006-03-11 14:32:36 【发表评论】 【查看原文】 【MySQL讨论区】【关闭】
mysql安装笔记

cloud/2003.10.10
mail:flashc@21cn.com
欢迎转载,转载请保留上述信息,谢谢

学习了很长时间的linux,有必要做一下整理笔记了,以下是mysql的安装笔记,和常见的一些使用方法。
因我喜欢调试优化系统,所以在编译安装时使用了一些选项增加编程后程序的执行效率,有些可能我理解有错,希望大家指出.

●安装mysql
# tar zxvf mysql-4.0.14.tar.gz -C /setup
# cd /setup/mysql-4.0.14
# groupadd mysql
# useradd mysql -g mysql -M -s /bin/false
# ./configure --prefix=/web/mysql / 指定安装目录
      --without-debug /去除debug模式
      --with-extra-charsets=gb2312 /添加gb2312中文字符支持
      --enable-assembler /使用一些字符函数的汇编版本
      --without-isam /去掉isam表类型支持 现在很少用了 isam表是一种依赖平台的表
      --without-innodb /去掉innodb表支持 innodb是一种支持事务处理的表,适合企业级应用
      --with-pthread /强制使用pthread库(posix线程库)
      --enable-thread-safe-client /以线程方式编译客户端
      --with-client-ldflags=-all-static /
      --with-mysqld-ldflags=-all-static /以纯静态方式编译服务端和客户端       --with-raid /激活raid支持
     
# make
# make install      
# scripts/mysql_install_db /生成mysql用户数据库和表文件
# cp support-files/my-medium.cnf /etc/my.cnf /copy配置文件,有large,medium,small三个环境下的,根据机器性能选择,如果负荷比较大,可修改里面的一些变量的内存使用值
# cp support-files/mysql.server /etc/init.d/mysqld  /copy启动的mysqld文件
# chmod 700 /etc/init.d/mysqld
# cd /web
# chmod 750 mysql -R
# chgrp mysql mysql -R
# chown mysql mysql/var -R
# cd /web/mysql/libexec
# cp mysqld mysqld.old
# strip mysqld
# chkconfig --add mysqld
# chkconfig --level 345 mysqld on
# service mysqld start
# netstat -atln
看看有没有3306的端口打开,如果mysqld不能启动,看看/web/mysql/var下的出错日志,一般都是目录权限没有设置好的问题
# ln -s /web/mysql/bin/mysql /sbin/mysql
# ln -s /web/mysql/bin/mysqladmin /sbin/mysqladmin
# mysqladmin -uroot password "youpassword" #设置root帐户的密码
# mysql -uroot -p
# 输入你设置的密码
mysql>;use mysql;
mysql>;delete from user where password=""; #删除用于本机匿名连接的空密码帐号
mysql>;flush privileges;
mysql>;quit

●安装DBI和DBD for mysql 用于提供perl访问mysql数据库的接口规范,请确认你已经安装了perl,一般默认系统都装上了

# cd /setup
# tar zxvf DBD-mysql-2.9002.tar.gz -C /setup
# tar zxvf DBI-1.38.tar.gz -C /setup
# cd DBI-1.38
# perl Makefile.PL
# make 
# make test
# make install
因为有的perl程序中perl的路径是/usr/local/bin/perl,而红帽系统默认是/usr/bin/perl,所以最好做一个连接,保证兼容性
# ln -s /usr/bin/perl /usr/local/bin/perl
# cd ../DBD-mysql-2.9002
生成安装配置文件需要在perl Makefile.PL后添加一些参数,比较麻烦,我们可以通过添加一个到/web/mysql/bin/mysql_config这个程序的连接解决问题
系统会自动寻找这个命令生成安装所需要的数据库参数
# ln -s /web/mysql/bin/mysql_config  /sbin/mysql_config
# perl Makefile.PL
# make 
# make instll (这里make test我总是运行一半就出错,但是安装后是可以运行mysql目录下的测试脚本,不知道3.x的mysql如何)
现在你可以运行测试脚本了,不过速度很慢,挂在后台好了
# perl /web/mysql/sql-bench/run-all-tests --user=root --password="youpassword"


附:
●mysql常见的一些有用的选项和命令
mysqld -----开启日志支持
--log 
--log-update
--log-long-formart
●mysql
grant all on database.* to user identified by "password" 新建一user用户,赋予其database数据库的所有权限
revoke all on database from user 移除user用户在database数据库上的所有权限
mysql -uroot -p --one-database databasename < file.sql 从file.sql文件导入sql语句到databasename这个数据库里
●mysqladmin
mysqladmin flush-logs 命令mysqld重新打开一个新的日志文件,就是清空老日志文件,相当于轮回了
●mysqldump 
--add-drop-table 导出sql语句时添加droptable if exists语句
--quick 快速导出
--opt  优化选项(推荐)
●myisamchk
检查表选项
--extend-check 扩展检查
--medium-check 速度比较折中的一个检查选项
修复表选项
--recover 修复表文件
--safe-recover 安全修复表文件,比--recover要慢
修饰修复表项
--force 强制清除上次的临时文件
--quick 只根据素引文件的内容进行修复
●mysql的管理
可以使用phpmyadmin(需要php的环境支持)和mysqlcc(linux图形界面支持,WINDOWS系统支持)



 geniusdao 回复于:2003-10-15 21:54:31

楼主,我按照你的方法去做,可是解压以后执行./configure --prefix=/web/mysql 后,往下在接着执行make 怎么执行不了呢?提示没有makefile found 之类的话。也没有install文件生成阿。请解释一下好吗?急等!


 cloudxx 回复于:2003-10-16 00:06:01

那肯顶是你的configure没有完成 可能出错了吧  注意看下输出


 Trotter 回复于:2003-10-16 08:40:11

不错,加为精华,支持一下,继续努力。


 geniusdao 回复于:2003-10-16 10:14:18

你的意思是说,只有configure正确后才能出现install这个文件吗?我觉得我的configure挺正确的,但是我运行的时候它的提示好象 说,这个版本是一个已经config后的,可以直接使用。我不知道你运行configure后提示的是什么话。是不是我下载的版本有问题啊?我是在 mysql的网站上linux页面第一行的那个版本mysql-standard-4.0.15-pc-linux-i686.tar.gz。我不知道是 不是你所说的那个版本。


 cloudxx 回复于:2003-10-16 10:26:42

你下的不是源代码版本的吧?


 cloudxx 回复于:2003-10-16 10:26:57

你下的不是源代码版本的吧?看写README  和INSTALL文当吧


 geniusdao 回复于:2003-10-16 13:27:20

哥们,能不能给我一个源代码下载的连接,现在我很迷茫,麻烦,谢了!


 gunguymadman007 回复于:2003-10-16 14:09:34

ding


 geniusdao 回复于:2003-10-16 17:49:20

别光顶阿,有知道的朋友,告诉一下阿


 cloudxx 回复于:2003-10-16 19:26:04

http://www.mysql.com/downloads/mysql-4.0.html

Source downloads
Compiler Advisory: Several users have reported random crashes and table corruptions when using MySQL binaries compiled with gcc 2.96 on the x86 Linux platform. We suggest that you use gcc 2.95 or gcc 2.91 to compile your own binaries. It should also be safe to use gcc 3.2.

For maximum stability and performance, we recommend that you use the binaries we provide.

Tarball (tar.gz)  4.0.15a 12.2M Download


 geniusdao 回复于:2003-10-16 20:19:24

thanks


 jakechen 回复于:2003-10-16 22:56:01

引用:原 帖由 "geniusdao"]楼主,我按照你的方法去做,可是解压以后执行./configure --prefix=/web/mysql 后,往下 在接着执行make 怎么执行不了呢?提示没有makefile found 之类的话。也没有install文件生成阿。请解释一下好吗?急等!
 发表:



老大,你下的是二进制包,编译好了的,直接接压缩到相关目录就可以了,

顺便谢谢楼上的教学。


 ss0616 回复于:2003-10-17 10:30:51

引用:原帖由 "cloudxx" 发表:
http://www.mysql.com/downloads/mysql-4.0.html

Source downloads
Compiler Advisory: Several users have reported random crashes and table corruptions when using MySQL binaries compiled with gcc 2.96 ..........



不要笑我,我刚开始学这个。
问一下,Linux (Alpha)分三种下载:Standard,Max,Debug。它们有什么区别吗?


 cloudxx 回复于:2003-10-17 11:14:20

看字面意思吧   标准,最大,除错 三种编译包


 ss0616 回复于:2003-10-17 11:37:08

引用:原帖由 "cloudxx"]看字面意思吧   标准,最大,除错 三种编译包
 发表:


三个安装好了没什么区别吧??最后一个包是其它两个包的一倍。


 geniusdao 回复于:2003-10-18 18:14:27

引用:原帖由 "cloudxx"]你下的不是源代码版本的吧?
 发表:


我如果下的不是源代码的版本,那改如何安装和设置呢?我已经安装了1个礼拜了。使用你的方法安装源代码也不好用,总是说找不到 /tmp/mysql。stock。但是已经又这个文件了,不过我看字节是0。我看还是用直接安装的那个文件安装吧(mysql-standard- 4.0.15-pc-linux-i686.tar.gz),楼主知道怎么安装和设置吗?


 suncqq 回复于:2003-10-19 19:54:49

老大,俺想请教一个问题!!!
俺用的mysql直接解压就可以用了,不用编译的,版本是:mysql-4.0.13.tar.gz

俺是创建mysql用户,启动数据库的时候提示如下错误:
再执行这个语句:/usr/local/mysql/bin/mysqld_safe --user=mysql &
显示如下:
[1] 24154
[root@localhost bin]# The file /usr/local/mysql/libexec/mysqld doesn't exist or is not 

executable
Please do a cd to the mysql installation directory and restart
this script from there as follows:
./bin/mysqld_safe.

查看错误日志提示如下:

/usr/local/mysql/bin/mysqld: ERROR: unknown option '--log-bin             # required for replication'
031012 10:00:04  mysqld ended


到底是什么原因呢?


 cloudxx 回复于:2003-10-19 20:00:04

目录权限呢?是否建了mysql这个用户呢?看日志你好象是加了错误的选项了 可是你的操作没有  怪呢
不行就编译一个吧  我的操作基本是一步一步来的 照着来一定不会有错


 suncqq 回复于:2003-10-19 20:08:48

引用:原帖由 "cloudxx" 发表:
目录权限呢?是否建了mysql这个用户呢?看日志你好象是加了错误的选项了 可是你的操作没有  怪呢
不行就编译一个吧  我的操作基本是一步一步来的 照着来一定不会有错



俺是这样安装和启动mysql数据库的!!!

groupadd mysql
useradd -g mysql mysql
cd /usr/local
gunzip < /usr/local/mysql-standard-4.1.0-alpha-pc-linux-i686.tar.gz | tar xvf -
ln -s /usr/local/mysql-standard-4.1.0-alpha-pc-linux-i686 mysql
cd mysql
scripts/mysql_install_db
chown -R root .
chown -R mysql data
chgrp -R mysql .
运行MySQL:
./bin/mysqld_safe --user=mysql &

有问题么?


 zenisys 回复于:2003-10-20 23:50:11

多写


 冰魂 回复于:2003-10-22 12:03:49

我的MYSQL无法启动
查看日志如下:

031022 11:47:16  mysqld started
031022 11:47:16  Fatal error: Can't open privilege tables: Table 'mysql.host' doesn't exist
031022 11:47:16  Aborting


mysql.host表不存在。那就是在创建表的时候出了问题。
这是我建表的记录:
[root@localhost mysql-4.0.15a]# scripts/mysql_install_db
Preparing db table
Preparing host table
Preparing user table
Preparing func table
Preparing tables_priv table
Preparing columns_priv table
Installing all prepared tables
mysqld got signal 11;
This could be because you hit a bug. It is also possible that this binary
or one of the libraries it was linked against is corrupt, improperly built,
or misconfigured. This error can also be caused by malfunctioning hardware.
We will try our best to scrape up some info that will hopefully help diagnose
the problem, but since we have already crashed, something is definitely wrong
and this may fail.

key_buffer_size=16777216
read_buffer_size=131072
max_used_connections=0
max_connections=100
threads_connected=1
It is possible that mysqld could use up to
key_buffer_size + (read_buffer_size + sort_buffer_size)*max_connections = 80383
K
bytes of memory
Hope that's ok; if not, decrease some variables in the equation.

thd=0x8290d48
Attempting backtrace. You can use the following information to find out
where mysqld died. If you see no messages after this, something went
terribly wrong...
Cannot determine thread, fp=0xbf5fea68, backtrace may not be correct.
Stack range sanity check OK, backtrace follows:
0x808aa06
0x8153b0c
0x816a396
0x809ad75
0x809db1f
0x809ab94
0x8095484
0x814ef61
0x818aafa
scripts/mysql_install_db: line 1:  5141 Segmentation fault      /usr/local/mysql/libexec/mysqld --bootstrap --skip-grant-tables --basedir=/usr/local/mysql --datadir=/usr/local/mysql/var --skip-innodb --skip-bdb
Installation of grant tables failed!

Examine the logs in /usr/local/mysql/var for more information.
You can also try to start the mysqld daemon with:
/usr/local/mysql/libexec/mysqld --skip-grant &
You can use the command line tool
/usr/local/mysql/bin/mysql to connect to the mysql
database and look at the grant tables:

shell>; /usr/local/mysql/bin/mysql -u root mysql
mysql>; show tables

Try 'mysqld --help' if you have problems with paths. Using --log
gives you a log in /usr/local/mysql/var that may be helpful.

The latest information about MySQL is available on the web at
http://www.mysql.com
Please consult the MySQL manual section: 'Problems running mysql_install_db',
and the manual section that describes problems on your OS.
Another information source is the MySQL email archive.
Please check all of the above before mailing us!
And if you do mail us, you MUST use the /usr/local/mysql/bin/mysqlbug script!


哪位大哥帮我看看啊。


 冰魂 回复于:2003-10-22 13:43:48

解决了,configure的时候我只加了--prefix的参数。
不过我不清楚为什么要加别的参数,


 ss0616 回复于:2003-10-25 08:33:41

我的也OK了~~谢谢


 wjger 回复于:2003-10-31 09:13:18

我在redhat9下严格按照老大的步骤安装,但在执行命令时scripts/mysql_install_db不能创建表,不知为什么?


 cloudxx 回复于:2003-10-31 13:03:00

出错信息呢  ?


 蓝色虫 回复于:2003-10-31 15:12:33

uping...


 jjlovelml 回复于:2006-02-13 19:47:03

感谢搂组的好文章


 donee 回复于:2006-03-07 12:14:11

是不是没有装一些开发软件啊,如gcc.........


 jianghao0726 回复于:2006-03-10 17:03:59

你的是以经编译好的了,建完用户,就可以用了


 fuxinrong 回复于:2006-03-11 14:29:52

我按你写的步骤去安装,在添加用户组及用户时出问题了!这是怎么回事?
[fuxinrong@localhost fuxinrong]$ su root
Password:
[root@localhost fuxinrong]# groupadd mysql
bash: groupadd: command not found
[root@localhost fuxinrong]#

楼主帮帮我啊!!!


 fuxinrong 回复于:2006-03-11 14:32:36

[fuxinrong@localhost fuxinrong]$ su root
Password:
[root@localhost fuxinrong]# groupadd mysql
bash: groupadd: command not found
[root@localhost fuxinrong]#
我的groupadd命令怎么用不了????请各位高手帮忙!!!!!




原文链接:http://bbs.chinaunix.net/viewthread.php?tid=178508
转载请注明作者名及原文出处