首页 > 代码库 > Mysql快速配置安装方法

Mysql快速配置安装方法

一. 前言

由于mysql 5.5.7之后使用cmake编译。本篇简单介绍mysql的安装和配置。

二. 环境准备

1.操作系统
CentOS 6.4 x86_64
2.软件版本
mysql-5.5.37   #下载地址:http://dev.mysql.com/downloads/file.php?id=451429 ,需要申请oracle账号才能下载。
3.需要安装的依赖包
cmake
gcc
gcc-c++
ncurses-devel
bison
openssl-devel
4. 安装过程:
  • 创建mysql用户,以及数据目录(家目录)

#mkdir -p /mydata/data
#groupadd -r mysql
#useradd -g mysql -r -d /mydata/data mysql
  • 解压mysql5.5.37的源码包到指定目录

#tar -zvxf mysql-5.5.37.tar.gz -C /tmp
  • 使用cmake 编译安装mysql5.5.37

#cd /tmp/mysql-5.5.37
#cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/mydata/data \
-DSYSCONFDIR=/etc \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DWITH_SSL=system \
-DWITH_ZLIB=system \
-DWITH_LIBWRAP=0 \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci
#make&&make install
##如果编译出错,解决问题后重新编译需要删除当前目录下(/tmp/mysql-5.5.37)的CMakeCache.txt。然后重新编译。
  • 复制配置文件

#cp /usr/local/mysql/support-files/my-large.cnf /etc/my.cnf
  • 复制启动脚本和配置开机自动启动

#cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
#chmod +x /etc/init.d/mysqld
#chkconfig –add mysqld
#chkconfig mysqld on
  • 修改my.cnf配置

#vim /etc/my.cnf
##在[mysqld]下添加:
datadir=/usr/local/mysql/data

初始化数据库

#/usr/local/mysql/scripts/mysql_install_db --user=mysql--basedir=/usr/local/mysql --datadir=/mydata/data

  • 启动mysqld

#service mysqld start
  • 由于mysql客户端所在目录不在PATH(环境变量),所以需要添加到PATH中

#vim /etc/profile.d/mysql.sh
export PATH=/usr/local/mysql/bin:$PATH
  • 执行mysql客户端连接。

[root@test01 support-files]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version:5.5.37-log Source distribution

Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type ‘help;‘or‘\h‘for help. Type ‘\c‘ to clear the current input statement.

mysql>

  • 删除匿名用户

mysql>DROP USER ‘‘@localhost;
mysql>DROP USER ‘‘@test01;
  • 为root账户添加密码

mysql>UPDATE user SET password=PASSWORD(‘password‘) WHERE user=‘root‘;
或者
[root@test01 support-files]# mysqladmin -u root password ‘password‘
  • 如果root密码忘记了,修改/etc/init.d/mysqld,修改前别忘记备份。修改完成后重新启动mysqld

原文件:
case "$mode" in
 ‘start‘)
   cd $basedir
echo $echo_n "Starting MySQL"
iftest -x $bindir/mysqld_safe
then
     $bindir/mysqld_safe --datadir="$datadir" --pid-file="$mysqld_pid_file_path" $other_args >/dev/null 2>&1 &
     wait_for_pid created "$!" "$mysqld_pid_file_path"; return_value=http://www.mamicode.com/$?
iftest -w "$lockdir"
then
       touch "$lock_file_path"
fi
exit $return_value
else
     log_failure_msg "Couldn‘t find MySQL server ($bindir/mysqld_safe)"
fi
   ;;
修改后:
case "$mode" in
 ‘start‘)
   cd $basedir
echo $echo_n "Starting MySQL"
iftest -x $bindir/mysqld_safe
then
     $bindir/mysqld_safe --datadir="$datadir" --pid-file="$mysqld_pid_file_path" --skip-grant --skip-networking $other_args >/dev/null 2>&1 &
     wait_for_pid created "$!" "$mysqld_pid_file_path"; return_value=http://www.mamicode.com/$?
iftest -w "$lockdir"
then
       touch "$lock_file_path"
fi
exit $return_value
else
     log_failure_msg "Couldn‘t find MySQL server ($bindir/mysqld_safe)"
fi
   ;;


本文出自 “王振园的技术博客” 博客,请务必保留此出处http://andriy1234.blog.51cto.com/826703/1411884