mysql5.5安装例子一
——————————————————————
在linux下mysql 5.5安装 2011-08-10
1、安装所需要系统库相关库文件
2、创建mysql安装目录
# mkdir -p /usr/local/mysql/
3、创建数据存放目录
# mkdir -p /service/mysql/
4、创建用户和用户组与赋予数据存放目录权限
# groupadd mysql
# useradd -g mysql mysql
# chown mysql.mysql -R /service/mysql/
5、安装cmake(mysql5.5以后是通过cmake来编译的)
# wget http://www.cmake.org/files/v2.8/cmake-2.8.5.tar.gz
# tar zxvf cmake-2.8.4.tar.gz
# cd cmake-2.8.4
#./configure
# make && make install
6、下载解压mysql 5.5.15
wget http://mirrors.sohu.com/mysql/MySQL-5.5/mysql-5.5.15.tar.gz
[root@localhost down]# tar zxvf mysql-5.5.15.tar.gz
[root@localhost down]# cd mysql-5.5.15
7、编辑mysql
cmake . \
> -DCMAKE_INSTALL_PREFIX=/usr/local/mysql\
> -DMYSQL_DATADIR=/service/data/\
> -DMYSQL_UNIX_ADDR=/service/data/mysqld.sock\
> -DWITH_INNOBASE_STORAGE_ENGINE=1\
> -DSYSCONFDIR=/etc\
> -DEXTRA_CHARSETS=all\
> -DDEFAULT_CHARSET=utf8\
> -DDEFAULT_COLLATION=utf8-general_ci\
> -DMYSQL_USER=mysql\
> -DWITH_DEBUG=0
-DMYSQL_UNIX_ADDR=/service/data/mysqld.sock\
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_EXTRA_CHARSETS:STRING=utf8,gbk \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DMYSQL_DATADIR=/service/data/\
-DMYSQL_USER=mysql
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/service/data/ -DMYSQL_UNIX_ADDR=/service/data/mysqld.sock -DWITH_INNOBASE_STORAGE_ENGINE=1 -DSYSCONFDIR=/etc -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_unicode_ci -DWITH_DEBUG=0
源代码配置选项说明:
//mysql安装的主目录,5.5.8版本默认为/usr/local/mysql,所以可以不添加
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql
//mysql数据保存的路径,自定义
-DMYSQL_DATADIR=/home/system_username/mysql/mysqldata
//mysql配置文件地址------The default my.cnf option file directory
-DSYSCONFDIR=/etc
//Compile storage engine xxx statically into server
/*Storage engines are built as plugins. You can build a plugin as a static module (compiled into the server)
*or a dynamic module (built as a dynamic library that must be installed into the server using the INSTALL
*PLUGIN statement or the --plugin-load option before it can be used). Some plugins might not support static
*or dynamic building.
*/
-DWITH_INNOBASE_STORAGE_ENGINE=1
-DWITH_ARCHIVE_STORAGE_ENGINE=1
-DWITH_BLACKHOLE_STORAGE_ENGINE=1
-DWITH_FEDERATED_STORAGE_ENGINE=1
-DWITH_PARTITION_STORAGE_ENGINE=1
//Unix socket file
/*
*The Unix socket file path on which the server listens for socket connections. This must be an absolute path
*name. The default is /tmp/mysql.sock
*/
-DMYSQL_UNIX_ADDR=/tmp/mysqld.sock
//数据库服务器TCP/IP连接的监听端口,默认为3306
-DMYSQL_TCP_PORT=3306
//Whether to enable LOCAL capability in the client library for LOAD DATA INFILE
//默认为关闭,这里开启
-DENABLED_LOCAL_INFILE=1
//数据库编码设置
-DEXTRA_CHARSETS=all
-DDEFAULT_CHARSET=utf8
-DDEFAULT_COLLATION=utf8-general_ci
8、make && make install
9、
cp support-files/my-medium.cnf /etc/my.cnf
cp support-files/mysql.server /etc/init.d/mysqld
chmod 755 /etc/init.d/mysqld
bash scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/service/data/
/etc/init.d/mysqld start
/usr/local/mysql/bin/mysql -u root -p
mysql>use mysql ;
mysql>update user set password=PASSWORD("bjsyx825") where user='root';
mysql>FLUSH PRIVILEGES;
——————————————————————
mysql5.5安装例子二
——————————————————————
mysql5.5安装2011年
mysql 5.5 以后的tar包居然是用cmake来进行安装的,而不是之前的Autotools方式即(configure方式)
所以还是记录一下安装过程,以备后记。
首先是下载tar包,大概22M的样子,我自己下载的是5.5.10的版本。
然后是安装一些必备的工具
1 sudo apt-get install cmake libncurses5-dev g++
然后是通过cmake来进行编译
1 cmake -DCMAKE_INSTALL_PREFIX=/usr/local -DMYSQL_DATADIR=/home/server/mysqldata -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DMYSQL_UNIX_ADDR=/tmp/mysqld.sock -DWITH_DEBUG=0 -DWITH_INNOBASE_STORAGE_ENGINE=1
具体可以参考http://forge.mysql.com/wiki/Autotools_to_CMake_Transition_Guide
这是mysql开发者写的一个autools转换岛对应的cmake的各种编译参数的对比资料。
1 make
2 sudo make install
这样安装就算完成了
后面的步骤就跟之前的一样了。
安装mysql库
1 mysql_install_db --user=mysql --basedir=/usr/local --datadir=/home/server/mysqldata --no-defaults
这里一定要加上no-defaults参数,不然程序会自动载入配置文件。
拷贝启动文件和my.cnf文件
1 sudo cp /usr/local/support-files/mysql.server /etc/init.d/mysqld
2 sudo cp /usr/local/support-files/my-innodb-heavy-4G.cnf /etc/mysql/my.cnf
修改my.cnf文件
1 [mysqld]
2 basedir=/usr/local
3 datadir=/home/server/mysqldata
4 user=mysql
启动并加入启动项
1 /etc/init.d/mysqld start
2 chkconfig mysqld on
为了方便以后安装,最好将这个编译成deb或者rpm包