Linux下编译安装MySQL 5.5.23

实验室的Ubuntu 10.04上apt只能安装MySQL 5.1,忍不了,手动编译5.5。

折腾了一下午,5.5之后的源码安装各种坑爹啊,感谢这篇文章,《Ubuntu 10.04.2上编译安装MySQL 5.5.11》

1、下载

wget -O mysql-5.5.23.tar.gz http://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.23.tar.gz/from/http://mysql.saudi.net.sa/

2、编译

cmake . -DCMAKE_INSTALL_PREFIX=/usr/mysql -DMYSQL_DATADIR=/usr/mysql/data -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DMYSQL_UNIX_ADDR=/tmp/mysqld.sock -DWITH_DEBUG=0 -DWITH_INNOBASE_STORAGE_ENGINE=1

上述的参数:默认安装在/usr/mysql下,数据在/usr/mysql/data下。

cmake后会生成用于make的Makefile,然后编译、安装:

make
sudo make install

3、配置

首先更改下目录的权限。

cd /usr/mysql/
sudo chown -R mysql:mysql .

然后安装默认数据库,一定注意最后那个no-default,没有这个选项不行……

sudo scripts/mysql_install_db --user=mysql --basedir=/usr/mysql --datadir=/usr/mysql/data --no-defaults

安装完成后,我们把mysql属用户权限改为root,data属用户单独改为mysql

chown -R root .
chown -R mysql data

拷贝配置文件:

sudo cp ./support-files/my-medium.cnf /etc/my.cnf

由于我们没有安装在默认的位置(实际是5.5的Makefile太脑残了,5.1.x的时候,如果安装目录更改,其他所有的cnf都会自动修正的),所以需要修改my.cnf:

vim /etc/my.cnf
[mysqld]
#添加如下行
basedir=/usr/mysql
datadir=/usr/mysql/data
user=mysql

4、运行

首先把启动脚本拷贝到init.d:

sudo cp ./support-files/mysql.server /etc/init.d/
sudo chmod 755 /etc/init.d/mysql.server

然后启动:

sudo /etc/init.d/mysql.server start

没其他意外的话,会启动成功的。

5、关于root密码

已经5.5时代了,就用mysql默认的工具改密码吧:

sudo bin/mysql_secure_installation





NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!


In order to log into MySQL to secure it, we'll need the current
password for the root user.  If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.

Set root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] n
 ... skipping.

By default, MySQL comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] y
 - Dropping test database...
ERROR 1010 (HY000) at line 1: Error dropping database (can't rmdir './test/', errno: 17)
 ... Failed!  Not critical, keep moving...
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y
 ... Success!

Cleaning up...



All done!  If you've completed all of the above steps, your MySQL
installation should now be secure.

Thanks for using MySQL!

现在这工具很全面啊,至此终于搞定5.5的编译安装。

2 thoughts on “Linux下编译安装MySQL 5.5.23

    1. coder4coder4 Post author

      恩,我知道,但是自己编译可以控制一些选项。最近手痒了,呵呵。

      Reply

Leave a Reply

Your email address will not be published.