Home  >  Article  >  Database  >  Linux下MySQL源码安装及问题解决

Linux下MySQL源码安装及问题解决

WBOY
WBOYOriginal
2016-06-07 16:52:531042browse

准备MySQL的源码,版本号为Mysql-5.0.20a.tar.gz,当然其它的也行,只做为测试.Linux用Red hat Linux as 4.安装步骤:1.解压Mysql-5.

准备MySQL的源码,版本号为Mysql-5.0.20a.tar.gz,当然其它的也行,只做为测试.Linux用Red Hat Linux as 4.

安装步骤:

1.解压Mysql-5.0.20a.tar.gz.

命令: tar -zxvf Mysql-5.0.20a.tar.gz

2.配置 Mysql

命令:./configure --prefix=/usr/local/mysql [--with-charset=gbk]

说明:安装到/usr/local/mysql(最好先创建该目录)下,语言用gbk(可选项).当然用别的也行,还有其它参数可以查看相关文档.

3.编译,安装

命令:

make //如果第一次make错误,,要先make clean再make

make install

这两个命令发的时间较长.

4.创建用户和组.

groupadd Mysql

useradd -g Mysql Mysql

5.进入Mysql目录.创建var目录.并把./share/mysql/my-medium.cnf 拷到mysql目录下并改名为my.cnf.

>mkdir var

>mv share/mysql/my-medium.cnf my.cnf

6.配置my.cnf

配置主要把安装的目录的那几项打开就行.

改动如下:

[client]
#password = your_password
port = 3306
socket = /tmp/Mysql3306.sock

# The Mysql server
[Mysqld]
port = 3306
socket = /tmp/Mysql3306.sock

打开下面几项

innodb_data_home_dir = =/usr/local/mysql/var/
innodb_data_file_path = ibdata1:10M:autoextend
innodb_log_group_home_dir = =/usr/local/mysql/var/
innodb_log_arch_dir = =/usr/local/mysql/var/

//我第一次configure时--prefix=后面的路径误写成/usr/lcoal/mysql 发现后删除该安装目录,再次安装时发现安装过程报错(又到/usr/lcoal/mysql下读文件),打开配置文件发现该选项中的路径都被系统改为/usr/lcoal/mysql/var --解决办法改正该路径,同时到mysql源码文件下执行make clean 再次make 就ok了

7.安装数据库

命令:./bin/mysql_install_db --defaults-file=/usr/local/mysql/my.cnf --user=Mysql

说明:必须用参数--defaults-file指定my.cnf,否则系统用默认的/etc/my.cnf.

8.安装完后,可以看到Mysql/var目录下有数据文件,然后在/usr/local/mysql 用下面命令设置权限:

shell> chown -R root .
shell> chown -R Mysql var
shell> chgrp -R Mysql .

9.启动数据库.

./bin/Mysqld_safe --defaults-file=/test/Mysql/my
.cnf --user=Mysql &

10.进入数据库.

./bin/Mysql -u root --socket=/tmp/Mysql3306 --defaults-file=/test/Mysql/my.cnf

默认时没有密码,当然如果你删除/etc/my.cnf,可以不要后面的--defaults-file=/test/Mysql/my.cnf

./bin/Mysql -u root --socket=/tmp/Mysql3306 也就行了,原因大家应该知道吧!

//如果系统已经安装的有mysql了,这时执行mysql会发现系统还是运行的原来的mysql

shell#mysql

这时需要停止旧mysql 然后执行如下命令:

#cd /usr/bin

#rm -rf mysql

#ln -s /usr/local/mysql/bin/mysql ./mysql

这时再次执行mysql就会执行新版本的mysql;由于以后可能会用到mysql的相关库及头文件建议执行如下操作:

#cp -r /usr/local/mysql/include/mysql/* /usr/include/mysql

11.设为服务并自启动

对于设置为服务只要把Mysql/share/Mysql/Mysql.server放到/etc/init.d/下改名为Mysql

命令:

mv share/Mysql/Mysql.server /etc/init.d/Mysql

chmod 775 /etc/init.d/Mysql

chkconfig --add Mysql

总结,这只是安装了一个3306端口的Mysql,如果要在装一个msyql,步骤一样,只要改动my.cnf文件的内容.

[client]
#password = your_password
port = 3310
socket = /tmp/Mysql3310.sock

# The Mysql server
[Mysqld]
port = 3310
socket = /tmp/Mysql3310.sock

ok!就到这吧! 

linux

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn