现在的位置: 首页 > 综合 > 正文

Linux安装mysql-5.0.56

2013年12月13日 ⁄ 综合 ⁄ 共 8764字 ⁄ 字号 评论关闭

Linux版本:CentOS


1.

Add a login user and group for mysqld to run as:
shell> groupadd mysql
shell> useradd -g mysql mysql

shell> tar -zxvf mysql_5.0.56.tar.gz

2.
vim /etc/rc.conf
HOSTNAME="myhost"

vim /etc/hosts
#ip-address hostname.domain.org hostname
127.0.0.1 localhost.localdomain localhost myhost
在最后增加myhost

Reboot,Or execute “hostname myhost”

原因如下:
MySQL during installation tries to create entries for both root@localhost and root@$hostname probably because of special meaning the name 'localhost' has in MySQL (you may see Invoking MySQL Programs in MySQL documentation; in short, 'localhost' means connecting
via unix socket, not tcp). Bizarre, IMO, but documented.

https://bbs.archlinux.org/viewtopic.php?id=42309

不设置带来的问题:
bin/mysql_install_db --user=mysql 时,会报错
ERROR: 1062  Duplicate entry 'localhost-' for key 1
120306 21:14:24 [ERROR] Aborting

3.
cd mysql-5.0.56
[root@myhost mysql-5.0.56]# ./configure --prefix=/usr/local/mysql --with-extra-charsets=utf8
可以通过./configure --help查看选项.
--prefix=/usr/local/mysql
--with-tcp-port=3309
--with-unix-socket=/tmp/mysql.sock
--with-charset=gbk
--with-extra-charsets=all
选项说明:
--prefix=/usr/local/mysql是指安装mysql的路径
这里我安装的路径是/usr/local/mysql,你可以指定不同的路径
--with-extra-charsets=all 让mysql支持多语言
常用的还有
--with-unix-socket-path=指定mysql.sock存放路径,如果不加这个参数的,默认mysql.sock存放路径是/tmp/mysql.sock

4.
make
make install

5.
把文件my.cnf文件放到/etc/目录下,让mysql服务器启动时能找到它。(安装了多个MYSQL后,把my.cnf文件拷贝到安装目录下)
安装好mysql后,配制文件应该在/usr/local/mysql/share/mysql目录中。
配制文件有几个,有my-huge.cnf、my-medium.cnf、my-large.cnf、my-small.cnf,不同的流量的网站和不同配制的服务器环境,当然需要有不同的配制文件了。一般的情况下,my-medium.cnf这个配制文件就能满足我们的大多需要。
[root@myhost mysql-5.0.56]# cp /usr/local/mysql/share/mysql/my-medium.cnf /etc/my.cnf

6.初始化数据库,创建MySQL授权表
cd /usr/local/mysql
[root@myhost mysql]# ls
bin  include  info  lib  libexec  man  mysql-test  share  sql-bench

[root@myhost mysql]# chown -R mysql .
[root@myhost mysql]# chgrp -R mysql .
[root@myhost mysql]# bin/mysql_install_db --user=mysql
Installing MySQL system tables...
120306 22:48:54 [Warning] option 'max_join_size': unsigned value 18446744073709551615 adjusted to 4294967295
120306 22:48:54 [Warning] option 'max_join_size': unsigned value 18446744073709551615 adjusted to 4294967295
OK
Filling help tables...
120306 22:48:54 [Warning] option 'max_join_size': unsigned value 18446744073709551615 adjusted to 4294967295
120306 22:48:54 [Warning] option 'max_join_size': unsigned value 18446744073709551615 adjusted to 4294967295
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/usr/local/mysql/bin/mysqladmin -u root password 'new-password'
/usr/local/mysql/bin/mysqladmin -u root -h myhost password 'new-password'

Alternatively you can run:
/usr/local/mysql/bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:
cd /usr/local/mysql ; /usr/local/mysql/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl
cd mysql-test ; perl mysql-test-run.pl

Please report any problems with the /usr/local/mysql/bin/mysqlbug script!

The latest information about MySQL is available on the web at

http://www.mysql.com

Support MySQL by buying support/licenses at http://shop.mysql.com

[root@myhost mysql]# ls
bin  include  info  lib  libexec  man  mysql-test  share  sql-bench  var
mysql目录下多了一个 var目录,在到var目录里面有两个目录 mysql、test。mysql目录下应该有一些文件,test目录应该是空的。
现在 var目录下只有两个目录没有别的文件,那是因为我们还没有启动mysql。

7.启动mysql
[root@myhost mysql]# chown -R root .
[root@myhost mysql]# chown -R mysql var
[root@myhost mysql]# bin/mysqld_safe --user=mysql &
[1] 16493
[root@myhost mysql]# Starting mysqld daemon with databases from /usr/local/mysql/var

判断mysql是否启动成功
[tian@myhost ~]$ netstat -atln  看看有没有3306的端口打开
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address               Foreign Address             State      
tcp        0      0 127.0.0.1:2208              0.0.0.0:*                   LISTEN      
tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      
tcp        0      0 0.0.0.0:111                 0.0.0.0:*                   LISTEN      
tcp        0      0 0.0.0.0:694                 0.0.0.0:*                   LISTEN      
tcp        0      0 127.0.0.1:631               0.0.0.0:*                   LISTEN      
tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      
tcp        0      0 127.0.0.1:2207              0.0.0.0:*                   LISTEN     
[tian@myhost ~]$ ps -a | grep mysql
16493 pts/3    00:00:00 mysqld_safe
16519 pts/3    00:00:00 mysqld
[tian@myhost ~]$ cd /usr/local/mysql/bin
[tian@myhost bin]$ ./mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.0.56-log Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql>
说明数据库已经正确启动。看看是不是有2个数据库,应该和var目录下的2个目录名字一样
mysql> show databases;        ;符号 是mysql结束符
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| test               |
+--------------------+
3 rows in set (0.00 sec)

8.设置密码
在mysql/bin目录下有个mysqladmin工具是用来管理和操作mysql用的
[root@myhost bin]# ./mysqladmin -u root password 123456
再次登录
[root@myhost bin]# ./mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
说明密码设置成功
[root@myhost bin]# ./mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.0.56-log Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql>

9.通过启动脚本启动mysql
在 /usr/local/mysql/share/mysql/目录下有一个 启动mysql的文件mysqld.server。
我们可以把他复制到/etc/rc.d/init.d/目录并且改名为mysql
[root@localhost mysql]#cp mysqld.server /etc/rc.d/init.d/mysql
启动:/etc/rc.d/init.d/mysql start
停止:/etc/rc.d/init.d/mysql stop
重启:/etc/rc.d/init.d/mysql restart

也可设为开机启动
[root@localhost mysql]#cp mysqld.server /etc/init.d/mysql
[root@localhost mysql]#chmod 755 /etc/init.d/mysql
chkconfig mysql on

10.错误
1)启动失败
可以查看var目录下的myhost.err获取错误信息。
[root@myhost var]# more myhost.err
120306 22:56:38  mysqld started
120306 22:56:38 [Warning] option 'max_join_size': unsigned value 18446744073709551615 adjusted to
120306 22:56:38 [Warning] option 'max_join_size': unsigned value 18446744073709551615 adjusted to
InnoDB: The first specified data file ./ibdata1 did not exist:
InnoDB: a new database to be created!
120306 22:56:38  InnoDB: Setting file ./ibdata1 size to 10 MB
InnoDB: Database physically writes the file full: wait...
120306 22:56:38  InnoDB: Log file ./ib_logfile0 did not exist: new to be created
InnoDB: Setting log file ./ib_logfile0 size to 5 MB
InnoDB: Database physically writes the file full: wait...
120306 22:56:39  InnoDB: Log file ./ib_logfile1 did not exist: new to be created
InnoDB: Setting log file ./ib_logfile1 size to 5 MB
InnoDB: Database physically writes the file full: wait...
InnoDB: Doublewrite buffer not found: creating new
InnoDB: Doublewrite buffer created
InnoDB: Creating foreign key constraint system tables
InnoDB: Foreign key constraint system tables created
120306 22:56:39  InnoDB: Started; log sequence number 0 0
120306 22:56:39 [Note] /usr/local/mysql/libexec/mysqld: ready for connections.
Version: '5.0.56-log'  socket: '/tmp/mysql.sock'  port: 3306  Source distribution

错误例子:
[root@localhost mysql]# bin/mysqld_safe &
[1] 14587
[root@localhost mysql]# Starting mysqld daemon with databases from /usr/local/mysql/var
STOPPING server from pid file /usr/local/mysql/var/localhost.localdomain.pid
050407 01:44:15 mysqld ended
[1]+ Done bin/mysqld_safe

看看错误消息:
[root@localhost mysql]# more /usr/local/mysql/var/localhost.localdomain.err
050407 01:47:18 mysqld started
/usr/local/mysql/libexec/mysqld: File './localhost-bin.1' not found (Errcode: 13)
050407 1:47:18 [ERROR] Could not use localhost-bin for logging (error 13). Turn
ing logging off for the whole duration of the MySQL server process. To turn it o
n again: fix the cause, shutdown the MySQL server and restart it.
050407 1:47:18 InnoDB: Operating system error number 13 in a file operation.
InnoDB: The error means mysqld does not have the access rights to
InnoDB: the directory.
InnoDB: File name ./ibdata1
InnoDB: File operation call: 'create'.
InnoDB: Cannot continue operation.
050407 01:47:18 mysqld ended
如果出现这种错误消息,说明是数据库目录权限的问题造成的。也就是无法在数据库的目录(var目录)中创建 ibdatal 文件。这时我们只要改变一下var目录的权限就可以了
[root@localhost mysql]#chmod -R 1777 var/
再次启动mysql,我们到 var 目录看看是不是多了几个文件
ibdata1
ib_logfile0
ib_logfile1

localhost.localdomain.err 这个就是刚才启动失败的错误日志,既然成功了,我们可以删除它,以后再次出现错误的话,系统会重建错误日志,这样查找错误也会比较容易。不过实际的网络管理中不推荐这样做。

2)mysql.sock文件不存在
Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock'(2)";
两个原因:
(1)是你的mysql.sock 文件不存在了

http://hi.baidu.com/yuanyang203/blog/item/899d81da4795aa3e32fa1c34.html

(2)安装了两个版本的MySQL
比如一个是rpm方式安装(在redhat系列上通常会有一个缺省安装的较低版本的 MySQL即是通过rpm方式安装的),另一个是用tgz包解压在/usr/local下安装的。而两个版本的mysqld和mysql缺省的 mysql.sock的路径是不同的。安装两个版本是没问题的,但要知道当前你执行的mysql和mysqld是否是同一版本的。而这一问题又往往被忽略,因为通常运行mysql和 mysqld都是不加绝对路径的,这时候就找的是缺省路径中的mysql和mysqld了,而又未必是你真正想用的那个版本。

http://www.cnitblog.com/jakiegu/archive/2009/09/22/40843.html

http://www.diybl.com/course/7_databases/mysql/Mysqljs/20091024/179939.html

rpm -qa | grep mysql
rpm -e   mysql   -nodependens

3)
mysql5.5以后是通过cmake来编译的

参考文章:

http://dev.mysql.com/doc/refman/5.0/en/installing-source-distribution.html

http://www.51testing.com/?uid-58025-action-viewspace-itemid-20356

抱歉!评论已关闭.