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

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

(1)先安装cmake(mysql5.5之后是经过cmake来编译的)mysql

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


(2)建立mysql的安装目录及数据库存放目录sql

[root@ rhel5~]#mkdir -p /usr/local/mysql   //安装mysql 
[root@ rhel5~]#mkdir -p /usr/local/mysql/data  //存放数据库

(3)建立mysql用户及用户组数据库

[root@ rhel5~]groupadd mysql
[root@ rhel5~]useradd -r -g mysql mysql

(4)安装mysql缓存

复制代码

[root@ rhel5 local]#tar -zxv -f mysql-5.5.10.tar.gz
[root@ rhel5 local]#cd mysql-5.5.10
[root@ rhel5 mysql-5.5.10]#cmake . \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci  \
-DEXTRA_CHARSETS=all \
-DENABLED_LOCAL_INFILE=1 
[root@ rhel5 mysql-5.5.10]#make
[root@ rhel5 mysql-5.5.10]#make install

复制代码

参数说明:bash

-DCMAKE_INSTALL_PREFIX=/usr/local/mysql //安装目录app

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

-DDEFAULT_CHARSET=utf8       //使用utf8字符spa

-DDEFAULT_COLLATION=utf8_general_ci  //校验字符rest

-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)设置目录权限

[root@ rhel5~]# cd /usr/local/mysql

[root@ rhel5 mysql]# chown -R root:mysql . //把当前目录中全部文件的全部者全部者设为root,所属组为mysql

[root@ rhel5 mysql]# chown -R mysql:mysql data

(2)

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



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

[root@ rhel5 mysql]# cd /usr/local/mysql
[root@ rhel5 mysql]# scripts/mysql_install_db --user=mysql

(4)设置环境变量

复制代码

[root@ rhel5~]# vi /root/.bash_profile

在PATH=$PATH:$HOME/bin添加参数为:

PATH=$PATH:$HOME/bin:/usr/local/mysql/bin:/usr/local/mysql/lib

[root@ rhel5~]#source /root/.profile

复制代码

(5)手动启动mysql

复制代码

[root@ rhel5~]# cd /usr/local/mysql

[root@ rhel5 mysql]# ./bin/mysqld_safe --user=mysql &   //启动MySQL,但不能中止

启动日志写在此文件下:/usr/local/mysql/data/localhost.err

关闭MySQL服务

[root@ rhel5 mysql]# mysqladmin -u root -p shutdown  //这里MySQL的root用户尚未配置密码,因此为空值。须要输入密码时,直接点回车键便可。

复制代码

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

[root@ rhel5~]# service mysql.server start 
[root@ rhel5~]# service mysql.server stop
[root@ rhel5~]# service mysql.server restart

若是上述命令出现:mysql.server 未识别的服务

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

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

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

而后再用#service mysql start 来启动mysql便可。


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

复制代码

[root@ rhel5~]# mysql -u root mysql

mysql>use mysql;
mysql>desc user;
mysql> GRANT ALL PRIVILEGES ON *.* TO root@"%" IDENTIFIED BY "root";  //为root添加远程链接的能力。
mysql>update user set Password = password('xxxxxx') where User='root';
mysql>select Host,User,Password  from user where User='root'; 
mysql>flush privileges;
mysql>exit

从新登陆:mysql -u root -p

复制代码

注:若是不能远程链接

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

相关文章
相关标签/搜索