liunx系统中安装mysql的步骤:
1、下载liunx下的mysql
下载版本:5.6.40,通用版,linux下64位命令下载:wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.40-linux-glibc2.12-x86_64.tar.gz
2、卸载老版本的mysql
查找并删除mysql有关的文件
find / -name mysql
rm -rf 上边查找到的路径,多个路径用空格隔开
3、在安装目录下解压文件
*如果自己定义了安装路径,没有放在/usr/local下的话,后面的安装可能报错,我自己的路径就是在/usr/local/src/tools/mysql/mysql
tar -zxvf mysql-5.6.40-linux-glibc2.12-x86_64.tar.gz4、删除安装包
rm -rf mysql-5.6.40-linux-glibc2.12-x86_64.tar.gz
5、添加mysql用户组和mysql用户
先检查是否有mysql用户组和mysql用户
groups mysql
若无,则添加;
groupadd mysql
useradd -r -g mysql mysql
6、进入mysql目录更改权限
cd mysql/
chown -R mysql:mysql ./
7、执行安装脚本
./scripts/mysql_install_db --user=mysql
(报错:
FATAL ERROR: please install the following Perl modules before executing ./scripts/mysql_install_db:
Data::Dumper
解决办法:yum -y install autoconf
再次执行./scripts/mysql_install_db --user=mysql
报错:Installing MySQL system tables..../bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
解决办法:yum install libaio* -y)
安装完之后修改当前目录拥有者为root用户,修改data目录拥有者为mysql
chown -R root:root ./
chown -R mysql:mysql data
8、更改mysql密码
启动mysql,启动方法:./support-files/mysql.server start
9、MySQL启动之后再执行如下命令更改密码
./bin/mysqladmin -u root -h localhost.localdomain password 'root'
10、密码更改后即可登录MySQL
./bin/mysql -h127.0.0.1 -uroot -proot
登录之后将其他用户的密码也可改为root
update mysql.user set password=password('root') where user='root';
flush privileges;
11、增加远程登录权限
grant all privileges on *.* to root@'%' identified by 'root';
flush privileges;
12、将MySQL加入Service系统服务
cp support-files/mysql.server /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig mysqld on
service mysqld restart
service mysqld status