1.下载
mysql:http://www.mysql.com/downloads/ (需要注册ORACLE账号)
版本:mysql-advanced-5.6.21-linux-glibc2.5-x86_64.tar.gz
Linux版本:centos6.4 x64
2.安装
2.1通过SSH将mysql-advanced-5.6.21-linux-glibc2.5-x86_64.tar.gz上传到linux中/usr/local/目录下
2.2清楚原有的mysql: yum remove mysql
2.3安装mysql依赖包:
[root@localhost ~]# yum install gcc
[root@localhost ~]# yum install gcc-c++
[root@localhost ~]# yum install cmake
2.4增加mysql组和用户
[root@localhost ~]# groupadd mysql
[root@localhost ~]# useradd -g mysql mysql
2.5mysql解压安装重命名
[root@localhost ~]# tar -zxvf mysql-advanced-5.6.21-linux-glibc2.5-x86_64.tar.gz
[root@localhost ~]# mv mysql-advanced-5.6.21-linux-glibc2.5-x86_64.tar.gz mysql
2.6编译安装
[root@localhost mysql]# make && make install
2.7进入安装目录,将程序二进制的所有权改为root,数据目录的说有权改为mysql用户,更新授权表
[root@localhost mysql]# cd /usr/local/mysql/
[root@localhost mysql]# chown -R root .
[root@localhost mysql]# chown -R mysql .
[root@localhost mysql]# chgrp -R mysql .
[root@localhost mysql]# scripts/mysql_install_db --user=mysql
安全启动MySQL(默认密码为空)
[root@localhost mysql]#./bin/mysqld_safe --user=mysql&
2.8错误:
120908 00:16:25 mysqld_safe Logging to '/usr/local/mysql/data/CentOS.err'.
120908 00:16:26 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data
解决方法:将Centos.err的用户权限改为mysql用户
[root@CentOS ~]# cd /usr/local/mysql/data
[root@CentOS ~]# chgrp -R mysql CentOS.err
连接本机MySQL
[root@localhost mysql]#mysql –u root –p
提示输入password,默认为空,按Enter即可
断开连接
mysql>exit;
2.9为root账户设置密码
[root@localhost ~]# cd /usr/local/mysql/bin
[root@localhost mysql]# ./bin/mysqladmin -u root password 123456
Enter Password:123456
2.10
设置选项文件,将配置文件拷贝到/etc下
[root@localhost mysql]# cp support-files/my-medium.cnf /etc/mysql.cnf
[root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysql
[root@localhost mysql]# chmod +x /etc/init.d/mysql
[root@localhost mysql]# chkconfig mysql on
2.11通过服务来启动和关闭Mysql
[root@localhost ~]# service mysql start
[root@localhost ~]# service mysql stop
2.12.安装设置完毕,之后使用只需启动-连接-断开-关闭-重启,命令如下:
[root@CentOS mysql]# service mysql start
[root@CentOS mysql]# ./bin/ mysql -u root -p123456
mysql>exit;
[root@CentOS mysql]# service mysql stop
[root@CentOS mysql]# service mysql restart
3.设置mysql远程登录
3.1登录
[root@CentOS mysql]# ./bin/ mysql -u root -p123456
3.2授权root用户为任何ip都能登陆,并刷新
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '' WITH GRANT OPTION;
mysql> FLUSH PRIVILEGES;