1、创建相关目录用户
代码如下 | 复制代码 |
su – root groupadd mysql useradd -g mysql -p xifenfei -s /bin/bash -m mysql -d /opt/mysql MYSQL_BASE=/opt/mysql mkdir -p $MYSQL_BASE/product/5.5 mkdir -p $MYSQL_BASE/mysqldata mkdir -p $MYSQL_BASE/mysqllog mkdir -p /var/run/mysqld/ chmod -R 777 $MYSQL_BASE chown -R mysql:mysql $MYSQL_BASE chown -R mysql:mysql /var/run/mysqld |
3、环境变量配置
代码如下 | 复制代码 |
export MYSQL_BASE=/opt/mysql export basedir=$MYSQL_BASE/product/5.5 export datadir=$MYSQL_BASE/mysqldata export LD_LIBRARY_PATH=$basedir/lib:/lib:/usr/lib:/usr/local/lib export TMPDIR=/tmp export PATH=${PATH}:/usr/bin:/bin:/usr/bin/X11:/usr/local/bin export PATH=$basedir:$basedir/bin:${PATH}:$LD_LIBRARY_PATH |
4、调整mysql 用户系统限制(可选)
编辑文件:/etc/security/limits.conf 加入以下语句:
代码如下 | 复制代码 |
mysql soft nproc 2047 mysql hard nproc 16384 mysql soft nofile 1024 mysql hard nofile 65536 |
确认如下语句是否存在于/etc/pam.d/login,如果不存在请增加:
session required pam_limits.so
如果用户SHELL 用的是Bourne, Bash, 或者Korn shell 修改/etc/profile,并增加如
下内容。(在SuSe 操作系统上,则需要修改/etc/profile.local):
代码如下 | 复制代码 |
if [ $USER = "mysql" ]; then if [ $SHELL = "/bin/ksh" ]; then ulimit -p 16384 ulimit -n 65536 else ulimit -u 16384 -n 65536 fi fi |
5、安装数据库
5.1)解压数据库至/opt/mysql/product/5.5中
5.2)安装数据
代码如下 | 复制代码 |
[mysql@localhost ~]$ cd product/5.5/scripts/ [mysql@localhost scripts]$ ./mysql_install_db –basedir=$basedir –datadir=$datadir –user=mysql |
5.3)设置my.cnf参数
代码如下 | 复制代码 |
vi /etc/my.cnf [mysqladmin] |
5.4)异常处理
5.4.1)直接通过mysqld_safe不能正常启动数据库
代码如下 | 复制代码 |
ln -s /opt/mysql/product/5.5 /usr/local/mysql 或者 ln -s /opt/mysql/product/5.5/bin/mysqld /usr/local/mysql/bin/mysqld |
5.4.2)mysql_secure_installation不能正常执行
1)
执行:/opt/mysql/product/5.5/bin/mysql_secure_installation出现以下错误,解决方法(ln -s /var/run/mysqld/mysqld.sock /tmp/mysql.sock)
Enter current password for root (enter for none):
ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ (2)
2)
修改mysql_secure_installation 脚本的do_query 函数(推荐处理方法)
代码如下 | 复制代码 |
do_query() { echo “$1″ >$command #sed ‘s,^,> ,’ < $command # Debugging # mysql --defaults-file=$config <$command ----此行修改如下: mysql --defaults-extra-file=$config <$command return $? } |
6、添加开机启动服务
修改mysql.server文件
代码如下 | 复制代码 |
basedir=/opt/mysql/product/5.5 datadir=/opt/mysql/mysqldata [root@localhost ~]# cp /opt/mysql/product/5.5/support-files/mysql.server /etc/init.d/mysqld [root@localhost ~]# chkconfig –add mysqld [root@localhost ~]# chkconfig mysqld on [root@localhost ~]# chkconfig –list mysqld mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off |