Ubuntu 12.04 mysql 源码安装--mysql.5.5.x

前端之家收集整理的这篇文章主要介绍了Ubuntu 12.04 mysql 源码安装--mysql.5.5.x前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

1.假设已经有MysqL-5.5.25.tar.gz以及cmake-2.8.4.tar.gz两个源文件

(1)先安装cmake(MysqL5.5以后是通过cmake来编译的)

  1. [root@ rhel5 local]@H_404_5@#@H_404_5@apt-get install cmake


(2)创建MysqL的安装目录及数据库存放目录

  1. [root@ rhel5~]@H_404_5@#@H_404_5@mkdir -p /usr/local/MysqL //安装MysqL
  2. [root@ rhel5~]@H_404_5@#@H_404_5@mkdir -p /usr/local/MysqL/data //存放数据库

(3)创建MysqL用户用户

  1. [root@ rhel5~]groupadd MysqL
  2. [root@ rhel5~]useradd -r -g MysqL MysqL

(4)安装MysqL

  1. [root@ rhel5 local]@H_404_5@#@H_404_5@tar -zxv -f MysqL-5.5.10.tar.gz
  2. [root@ rhel5 local]@H_404_5@#@H_404_5@cd MysqL-5.5.10
  3. [root@ rhel5 MysqL-5.5.10]@H_404_5@#@H_404_5@cmake . \
  4. -DCMAKE_INSTALL_PREFIX=/usr/local/MysqL \
  5. -DMysqL_DATADIR=/usr/local/MysqL/data \
  6. -DDEFAULT_CHARSET=utf8 \
  7. -DDEFAULT_COLLATION=utf8_general_ci \
  1. -DEXTRA_CHARSETS=all \
  2. -DENABLED_LOCAL_INFILE=1
  3. [root@ rhel5 MysqL-5.5.10]@H_404_5@#@H_404_5@make
  4. [root@ rhel5 MysqL-5.5.10]@H_404_5@#@H_404_5@make install

参数说明:

-DCMAKE_INSTALL_PREFIX=/usr/local/MysqL //安装目录

-DINSTALL_DATADIR=/usr/local/MysqL/data //数据库存放目录

-DDEFAULT_CHARSET=utf8     //使用utf8字符

-DDEFAULT_COLLATION=utf8_general_ci //校验字符

-DEXTRA_CHARSETS=all     //安装所有扩展字符集

-DENABLED_LOCAL_INFILE=1    //允许从本地导入数据

cmake 的时候有报错,根据提示还需要 安装 g++ 等两个软件包

1

2

apt-get install g++

apt-get install libncurses5-dev

重新 cmake 之前一定要 执行

1

# rm -f CMakeCache.txt

注意事项:

重新编译时,需要清除旧的对象文件和缓存信息。

# make clean

# rm -f CMakeCache.txt

# rm -rf /etc/my.cnf

2.配置

(1)设置目录权限

  1. [root@ rhel5~]@H_404_5@#@H_404_5@ cd /usr/local/MysqL
  2.  
  3. [root@ rhel5 MysqL]@H_404_5@#@H_404_5@ chown -R root:MysqL . //把当前目录中所有文件的所有者所有者设为root,所属组为MysqL
  4.  
  5. [root@ rhel5 MysqL]@H_404_5@#@H_404_5@ chown -R MysqL:MysqL data

(2)

  1. [root@ rhel5 MysqL]@H_404_5@#@H_404_5@ cp support-files/my-medium.cnf /etc/my.cnf 



(3)创建系统数据库的表

  1. [root@ rhel5 MysqL]@H_404_5@#@H_404_5@ cd /usr/local/MysqL
  2. [root@ rhel5 MysqL]@H_404_5@#@H_404_5@ scripts/MysqL_install_db --user=MysqL

(4)设置环境变量

  1. [root@ rhel5~]@H_404_5@#@H_404_5@ vi /root/.bash_profile
  2.  
  3. PATH=$PATH:$HOME/bin添加参数为:
  4.  
  5. PATH=$PATH:$HOME/bin:/usr/local/MysqL/bin:/usr/local/MysqL/lib
  6.  
  7. [root@ rhel5~]@H_404_5@#@H_404_5@source /root/.profile

(5)手动启动MysqL

  1. [root@ rhel5~]@H_404_5@#@H_404_5@ cd /usr/local/MysqL
  2.  
  3. [root@ rhel5 MysqL]@H_404_5@#@H_404_5@ ./bin/MysqLd_safe --user=MysqL &   //启动MysqL,但不能停止
  4.  
  5. 启动日志写在此文件下:/usr/local/MysqL/data/localhost.err
  6.  
  7. 关闭MysqL服务
  8.  
  9. [root@ rhel5 MysqL]@H_404_5@#@H_404_5@ MysqLadmin -u root -p shutdown  //这里MysqL的root用户还没有配置密码,所以为空值。需要输入密码时,直接点回车键即可。

(6)另一种简单的启动MysqL方法(MysqL已经被添加到系统服务中)

  1. [root@ rhel5~]@H_404_5@#@H_404_5@ service MysqL.server start
  2. [root@ rhel5~]@H_404_5@#@H_404_5@ service MysqL.server stop
  3. [root@ rhel5~]@H_404_5@#@H_404_5@ service MysqL.server restart

如果上述命令出现:MysqL.server 未识别的服务

则可能MysqL还没添加到系统服务中,下面用另一种方法添加

  1. [root@ rhel5 MysqL]# cp support-files/MysqL.server /etc/init.d/MysqL @H_404_5@//@H_404_5@将MysqL的启动服务添加到系统服务中

注意:主要是将MysqL.server拷贝到/etc/init.d中,命名为MysqL。本系统中,MysqL.server在/usr/local/MysqL/support-files/MysqL.server中。

然后再用#service MysqL start 来启动MysqL即可。


(7)修改MysqL的root用户的密码以及打开远程连接

  1. [root@ rhel5~]@H_404_5@#@H_404_5@ MysqL -u root MysqL
  2.  
  3. MysqL>use MysqL;
  4. MysqL>desc user;
  5. MysqL> GRANT ALL PRIVILEGES ON *.* TO root@"%" IDENTIFIED BY "root";  //为root添加远程连接的能力。
  6. MysqL>update user set Password = password('xxxxxx') where User='root';
  7. MysqL>select Host,User,Password from user where User='root';
  8. MysqL>flush privileges;
  9. MysqL>exit
  10.  
  11. 重新登录MysqL -u root -p

注:如果不能远程连接

MysqL>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '******' WITH GRANT OPTION;

猜你在找的Ubuntu相关文章