Centos下安装MySQL
参考:http://www.centoscn.com/CentosServer/sql/2013/0817/1285.html
http://blog.csdn.net/feng4656/article/details/11816027
安装环境:Linux服务器CentOS 5.5
安装版本:mysql-5.6.22.tar.gz
1、安装 cmake 编译器。
1)、下载cmake
#cd /usr/local/src
#wget http://www.cmake.org/files/v2.8/cmake-2.8.4.tar.gz
2)、解压cmake
#tar -zvxf cmake-2.8.4.tar.gz
3)、配置编译
#cd cmake-2.8.4
#yum -y install gcc
#yum -y install gcc-c++
#yum -y install ncurses-devel
#./configure
#make
#make install
2、安装MySQL
1)、下载MySQL。
#cd /usr/local/src
#wget dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.22.tar.gz
2)、添加必要的组和拥有者
#groupadd mysql
#useradd -r -g mysql mysql
3)、解压MySQL
#tar -zvxf mysql-5.5.9.tar.gz
4)、配置编译
如果是重装MySql,请先删除my.cnf如: rm -rf /etc/my.cnf
#mkdir /usr/local/mysql
#mkdir /usr/local/mysql/data
#cd /usr/local/src/mysql-5.5.9
#cmake .
#make && make install
注意事项:
默认情况下是安装在/usr/local/mysql
重新编译时,需要清除旧的对象文件和缓存信息。
# make clean
# rm -f CMakeCache.txt
# rm -rf /etc/my.cnf
[root@server182 ~]# chown -R mysql.mysql /usr/local/mysql
[root@server182 ~]# cd /usr/local/mysql/scripts
[root@server182 ~]# ./mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
[root@server182 ~]# cd /usr/local/mysql/support-files
[root@server182 support-files]# cp mysql.server /etc/rc.d/init.d/mysqld
[root@server182 support-files]# cp my-medium.cnf /etc/my.cnf
[root@server182 ~]# chkconfig --add mysqld
[root@server182 ~]# chkconfig mysqld on
[root@server182 ~]# service mysqld start
Starting MySQL SUCCESS!
启动成功 运行mysql 一直提示无命令 检查是否服务器无 MySQL client 安装即可
如果再出错 检查
/etc/init.d/mysql: line 256: my_print_defaults: command not found
解决方法: 检查/etc/my.cnf是否存在datadir和basedir如果没有请增加 datadir和basedir目录路径.
如下
[mysqld]
port = 3306
basedir =/usr/local/mysql
datadir =/usr/local/mysql/data
This entry was posted in Mysql. Bookmark the permalink.
参考:http://blog.knowsky.com/196597.htm
5)、修改MySQL的root用户的密码:
# 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
6)、导出数据库生成SQL脚本
mysqldump -h 192.168.200.18 -u root -p TestDB > TestDB.sql
<2>、测试mysql守护进程。
#cd /usr/local/mysql/mysql-test ;
#perl mysql-test-run.pl
备注:
启动出错ERROR2002 (参考:http://blog.csdn.net/wyzxg/article/details/4720041)
解决方法:
由于mysql 默认的mysql.sock 是在/var/lib/mysql/mysql.sock,但linux系统总是去/tmp/mysql.sock查找,所以会报错
[root@localhost ~]# find / -name mysql.sock
/var/lib/mysql/mysql.sock (或者原本是/tmp/mysql.sock)
为mysql.sock增加软连接(相当于windows中的快捷方式)。
ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock
如果上面find 出来的结果是 /tmp/mysql.sock
则:ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock
其他:
mysql -u root -p
mysql>insert into mysql.user(Host,User,Password) values("localhost","用户名",password("密码")); #创建用户
mysql>create database test; #创建数据库test
mysql>alter database charging character set utf8; #设置数据库test的编码格式
mysql>grant select,insert,update,delete,create,drop on test.* to 用户名@localhost identified by '密码'; #将test数据库授权给用户。
mysql>GRANT select,insert,update,delete,create,drop ON test.* TO '用户名'@'%' IDENTIFIED BY '密码' WITH GRANT OPTION; //授权远程登陆
mysql>flush privileges; //刷新权限