linux安装mysql

下载安装包:mysql-5.6.30-linux-glibc2.5-x86_64.tar.gz
1、卸载老版本MySQL,查找并删除mysql有关的文件
find / -name mysql
rm -rf /usr/local/mysql/ /usr/lib64/mysql /usr/share/mysql /var/lock/subsys/mysql /var/lib/mysql
find / -name mysql|xargs rm -rf

2、在安装包存放目录下执行命令解压文件
tar -zxvf mysql-5.6.30-linux-glibc2.5-x86_64.tar.gz
cp mysql-5.6.30-linux-glibc2.5-x86_64 /usr/local/mysql -r

3、添加mysql用户组和mysql用户
先检查是否有mysql用户组和mysql用户
groups mysql
若无,则添加;
groupadd mysql
useradd -r -g mysql mysql

若有,则跳过;
cd /usr/local/mysql/
chown -R mysql:mysql ./
cd /mnt/mysql/
chown -R mysql:mysql ./

4、执行安装
./scripts/mysql_install_db --user=mysql --datadir=/mnt/mysql

可能出现的问题
二进制安装mysql初始化出现:Installing MySQL system tables…/usr/local/mysql/bin/mysqld: error while loading shared
原因:缺少libaio库文件
解决方法:yum install libaio* -y

FATAL ERROR: please install the following Perl modules before executing /usr/local/mysql/scripts/mysql_install_db:
解决方法 :安装autoconf库
命令:yum -y install autoconf

如果出现pid无法访问 可能是数据盘没有访问权限
chown mysql:mysql -R /mnt/mysql/

5、安装完之后修改当前目录拥有者为root用户,修改data目录拥有者为mysql
chown -R root:root ./
chown -R mysql:mysql /mnt/mysql

6、启动mysql
cd /usr/local/mysql
./support-files/mysql.server start

7、将MySQL加入Service系统服务
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig mysqld on
service mysqld restart
service mysqld status
[root@AY13121413404985357fZ ~]# mysql -u root -p
-bash: mysql: command not found
[root@AY13121413404985357fZ ~]# ln -s /usr/local/mysql/bin/mysql /usr/bin
[root@AY13121413404985357fZ ~]# mysql -u root -p
首次回车进入,修改root密码
use mysql;
update user set password=passworD(“XXX”) where user=‘root’;
flush privileges;

你可能感兴趣的:(mysql)