> 数据库 > MySQL >

CentOS-6.5安装MySQL 5.6.17并修改MySQL的root用户密码

转载自 http://www.cnblogs.com/littlehb/archive/2013/04/02/2995007.html

Mysql 5.5以后使用了CMake进行安装,参考与以前的区别请参考:

http://www.blogjava.net/kelly859/archive/2012/09/04/387005.html
 

接上文。

1:下载:当前mysql版本到了5.6.17

wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.17.tar.gz

2:必要软件包

yum -y install  gcc gcc-c++ gcc-g77 autoconf automake zlib* fiex* libxml* ncurses-devel libmcrypt* libtool-ltdl-devel* make cmake bison bison-devel


 

# 新增用户组
groupadd mysql

 

# 新增用户
useradd mysql -g mysql

 

# 新建数据库执行文件目录
mkdir -p /usr/local/mysql

 

# 新建数据库数据文件目录
mkdir -p /db/mysql/data

 

# 修改目录拥有者

chown -R mysql:mysql /usr/local/mysql

chown -R mysql:mysql /db/mysql/data

chown -R mysql:mysql /usr/local/mysql/.

chown -R mysql:mysql /db/mysql/data/.

 

# 编辑PATH搜索路径
vi /etc/profile
添加如下两行:


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

# 生效PATH搜索路径
source /etc/profile

 

# 安装编译源码所需的工具和库
yum -y install wget gcc-c++ ncurses-devel cmake make perl

# 进入源码压缩包下载目录
cd /usr/src

# 下载源码压缩包
wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.17.tar.gz

# 解压缩源码包
tar -zxv -f mysql-5.6.17.tar.gz

# 进入解压缩源码目录

cd mysql-5.6.17

# 编译并安装

复制代码

cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DMYSQL_DATADIR=/db/mysql/data \
-DMYSQL_USER=mysql \
-DMYSQL_TCP_PORT=3306


-DENABLE_DOWNLOADS=1(出现Googlemock was not found. 加上)


-DWITH_DEBUG=0

 
make && make install

红色部分表示禁用Debug模式。
复制代码
# 复制配置文件
cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf

# 进入安装路径
cd /usr/local/mysql

# 执行配置脚本
scripts/mysql_install_db --user=mysql --datadir=/db/mysql/data

# 复制服务启动脚本
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql

# 启动MySQL服务
service mysql start

# 设置开机自动启动服务
chkconfig mysql on

#添加系统变量

echo "PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:\$PATH" >> /etc/profile
echo "export PATH" >> /etc/profile
source /etc/profile

>>>>>>>>>>>>>>>完成

如果发生如下错误:

[root@rekfan mysql]# service mysql restart
MySQL server PID file could not be found![失败]
Starting MySQL...The server quit without updating PID file (/usr/local/mysql/data/rekfan.pid).[失败]

黄海的问题解决办法是:

killall命令
 
killall命令杀死同一进程组内的所有进程。其允许指定要终止的进程的名称,而非PID。
 
# killall mysqld
 
再次查看mysqld进程:
 
ps -ef|grep mysqld
 
没有了!世界清静了。
 
 

运行 mysql

然后进入mysql> 提示符后,输入status;

查看安装情况。

复制代码
mysql> status;
--------------
mysql  Ver 14.14 Distrib 5.6.10, for Linux (x86_64) using  EditLine wrapper

Connection id:          1
Current database:
Current user:           root@localhost
SSL:                    Not in use
Current pager:          stdout
Using outfile:          ''
Using delimiter:        ;
Server version:         5.6.10 Source distribution
Protocol version:       10
Connection:             Localhost via UNIX socket
Server characterset:    latin1
Db     characterset:    latin1
Client characterset:    latin1
Conn.  characterset:    latin1
UNIX socket:            /tmp/mysql.sock
Uptime:                 7 sec

Threads: 1  Questions: 5  Slow queries: 0  Opens: 67  Flush tables: 1  Open tables: 60  Queries per second avg: 0.714
--------------
复制代码
#表名全部为小写,避免出现大小写敏感

vi /etc/my.cnf 添加如下内容,解决大小写表名敏感问题。

lower_case_table_names=1
 

修改MySQL的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('123456') where User='root'; //设置root用户密码

mysql> select Host,User,Password from user where User='root';

mysql> flush privileges;

mysql> exit
复制代码
 

 

附自动安装脚本如下:

vi installmysql.sh

chmod 777 installmysql.sh

./installmysql.sh
 

内容如下:

复制代码
yum -y install wget gcc gcc-c++ gcc-g77 autoconf automake zlib* fiex* libxml* ncurses-devel libmcrypt* libtool-ltdl-devel* make cmake perl bison bison-devel

groupadd mysql
useradd mysql -g mysql
mkdir -p /usr/local/mysql
mkdir -p /db/mysql/data

chown -R mysql:mysql /usr/local/mysql
chown -R mysql:mysql /db/mysql/data
chown -R mysql:mysql /usr/local/mysql/.
chown -R mysql:mysql /db/mysql/data/.

echo "PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:\$PATH" >> /etc/profile
echo "export PATH" >> /etc/profile

source /etc/profile

cd /usr/software/
#下载mysql源码包
wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.17.tar.gz
tar -zxvf mysql-5.6.17.tar.gz
cd /usr/software/mysql-5.6.17
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_DATADIR=/db/mysql/data -DMYSQL_USER=mysql -DMYSQL_TCP_PORT=3306
make && make install

cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf
cd /usr/local/mysql
scripts/mysql_install_db --user=mysql --datadir=/db/mysql/data
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql

echo "lower_case_table_names=1" >> /etc/my.cnf

service mysql start
chkconfig mysql on

mysqladmin -u root password 'dsideal'

service iptables stop
chkconfig iptables off

sed -i 's#SELINUX=enforcing#SELINUX=disabled#'g /etc/sysconfig/selinux




(责任编辑:IT)