文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>(原创)MYSQL完全安装使用指南

(原创)MYSQL完全安装使用指南

时间:2007-02-17  来源:PHP爱好者

mysql安装笔记

cloud/2003.10.10
mail:[email protected]
欢迎转载,转载请保留上述信息,谢谢

学习了很长时间的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:34ding

geniusdao 回复于:2003-10-16 17:49:20别光顶阿,有知道的朋友,告诉一下阿

cloudxx 回复于:2003-10-16 19:26:04http://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:24thanks

jakechen 回复于:2003-10-16 22:56:01[quote:0fd7011cbd="geniusdao"]楼主,我按照你的方法去做,可是解压以后执行./configure --prefix=/web/mysql 后,往下在接着执行make 怎么执行不了呢?提示没有makefile found 之类的话。也没有install文件生成阿。请解释一下好吗?急等![/quote:0fd7011cbd]

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

顺便谢谢楼上的教学。

ss0616 回复于:2003-10-17 10:30:51[quote:ead28f2540="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 ..........[/quote:ead28f2540]

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

cloudxx 回复于:2003-10-17 11:14:20看字面意思吧   标准,最大,除错 三种编译包

ss0616 回复于:2003-10-17 11:37:08[quote:c32178bd7a="cloudxx"]看字面意思吧   标准,最大,除错 三种编译包[/quote:c32178bd7a]
三个安装好了没什么区别吧??最后一个包是其它两个包的一倍。

geniusdao 回复于:2003-10-18 18:14:27[quote:4152352a73="cloudxx"]你下的不是源代码版本的吧?[/quote:4152352a73]
我如果下的不是源代码的版本,那改如何安装和设置呢?我已经安装了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[quote:04f3ad4bf4="cloudxx"]目录权限呢?是否建了mysql这个用户呢?看日志你好象是加了错误的选项了 可是你的操作没有  怪呢
不行就编译一个吧  我的操作基本是一步一步来的 照着来一定不会有错[/quote:04f3ad4bf4]

俺是这样安装和启动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:33uping...
php爱好者站 http://www.phpfans.net 为phper提供一切资讯.
相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载