添加用户和用户组
- groupadd mysql
- useradd -g mysql mysql
解压mysql文件&0编译源代码
- tar zxvf mysql-5.1.65.tar.gz
- cd mysql-5.1.65
- ./configure --prefix=/usr/local/mysql/ --with-server-suffix=-zsd-edition --enable-assembler --enable-local-infile --enable-thread-safe-client --with-big-tables --with-charset=utf8 --with-extra-charsets=gbk,gb2312,utf8,ascii --with-readline --with-ssl --with-embedded-server --with-pthread --with-mysqld-user=mysql --with-mysqld-ldflags=-all-static --with-client-ldflags=-all-static --with-plugins=partition,innobase,innodb_plugin > /root/mysql_setuplogs_configure.log 2>&1
查看/root/mysql_setuplogs_configure.log,如果出现libtool的问题,按下述方法可解决
查看libtool是否已经安装。
1、确认libtool是否已经安装,如果没有安装的话,则先安装libtool
- # rpm -qa | grep libtool
- # yum -y install libtool
2、分别执行以下三条命令:
- # autoreconf --force --install
- # libtoolize --automake --force
- # automake --force --add-missing
make&安装:
- make > /root/mysql_setuplogs_make.log 2>&1
- make install > /root/mysql_setuplogs_makeinstall.log 2>&1
修改相关路径权限:
- cd /usr/local/
-
- chown -R mysql:mysql mysql
-
- mkdir -p /data/mysqldata/3306
- cd /data/mysqldata/3306
- mkdir data binlog tmp innodb_ts innodb_log
- chown -R mysql:mysql ./
创建mysql_install_db
- /usr/local/mysql/bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysqldata/3306/data
配置my.cnf
启动mysql服务:
- /usr/local/mysql/bin/mysqld_safe --defaults-file=/data/mysqldata/3306/my.cnf &
进入mysql:
- /usr/local/mysql/bin/mysql -uroot -S /data/mysqldata/3306/mysql.sock
关闭mysql:
- /usr/local/mysql/bin/mysqladmin -uroot -S /data/mysqldata/3306/mysql.sock shutdown
安装mysql后,对安全性做一点设置:
(1)删除掉不安全的用户:
- drop user ''@'localhost';
- drop user ''@'mysql-n1';
(2)为root用户设置密码:(以root用户登录)
- set password=password('zsd0507');
设置环境变量:
- sudo su - mysql
- vi /home/mysql/.bash_profile
- umask 022
- MYSQL_BASE=/usr/local/mysql
- MYSQL_HOME=/usr/local/mysql
- PATH=$MYSQL_BASE/bin:$PATH
- export PATH
- export MYSQL_BASE MYSQL_HOME
- 使得环境变量生效:
- source /home/mysql/.bash_profile
设置启动脚本(让它跟系统一起自动启动)
- cd /etc/init.d
- vi mysql
#!/bin/sh
mysql_port=3306
mysql_username="root"
mysql_password="zsd0507"
function_start_mysql()
{
printf "Starting MySQL...\n"
/bin/sh /usr/local/mysql/bin/mysqld_safe --defaults-file=/data/mysqldata/
${mysql_port}/my.cnf 2>&1 > /dev/null &
}
function_stop_mysql()
{
printf "Stoping MySQL...\n"
/usr/local/mysql/bin/mysqladmin -u ${mysql_username} -p${mysql_password} -S
/data/mysqldata/${mysql_port}/mysql.sock shutdown
}
function_restart_mysql()
{
printf "Restarting MySQL...\n"
function_stop_mysql
sleep 5
function_start_mysql
}
function_kill_mysql()
{
kill -9 $(ps -ef | grep 'bin/mysqld_safe' | grep ${mysql_port} | awk '{printf
$2}')
kill -9 $(ps -ef | grep 'libexec/mysqld' | grep ${mysql_port} | awk '{printf
$2}')
}
if [ "$1" = "start" ]; then
function_start_mysql
elif [ "$1" = "stop" ]; then
function_stop_mysql
elif [ "$1" = "restart" ]; then
function_restart_mysql
elif [ "$1" = "kill" ]; then
function_kill_mysql
else
printf "Usage: /data/mysqldata/${mysql_port}/mysql {start|stop|restart|
kill}\n"
fi
- chmod 755 mysql
到此,全部结束!~
阅读(2563) | 评论(0) | 转发(0) |