本地的安装环境: centos6.9
1、下载
mysql官网地址:
http://dev.mysql.com/downloads/mysql/5.6.html#downloads
我是用的版本:5.6.33,通用版,linux下64位
也可以直接复制64位的下载地址,通过命令下载:wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.33-linux-glibc2.5-x86_64.tar.gz
2、解压#解压 tar -zxvf mysql-5.6.33-linux-glibc2.5-x86_64.tar.gz #复制解压后的mysql目录 cp -r mysql-5.6.33-linux-glibc2.5-x86_64 /usr/local/mysql3、添加用户组和用户
#添加用户组 groupadd mysql #添加用户mysql 到用户组mysql useradd -g mysql mysql4、安装
cd /usr/local/mysql/<br>mkdir ./data/mysql chown -R mysql:mysql ./ ./scripts/mysql_install_db --user=mysql --datadir=/usr/local/mysql/data/mysql cp support-files/mysql.server /etc/init.d/mysqld chmod 755 /etc/init.d/mysqld cp support-files/my-default.cnf /etc/my.cnf
#修改启动脚本
vi /etc/init.d/mysqld
#修改项: basedir=/usr/local/mysql/ datadir=/usr/local/mysql/data/mysql
#启动服务 service mysqld start
#测试连接
./mysql/bin/mysql -uroot
#加入环境变量,编辑 /etc/profile,这样可以在任何地方用mysql命令了
export PATH=$PATH:/usr/local/mysql//bin
source /etc/profile
#启动mysql service mysqld start #关闭mysql service mysqld stop #查看运行状态 service mysqld status
5、常见问题汇总:
1、[root@iZ2zeg11g0cdei5171kqskZ mysql]# ./scripts/mysql_install_db --user=mysqlFATAL ERROR: please install the following Perl modules before executing ./scripts/mysql_install_db:Data::Dumper
解决
yum -y install autoconf
2、
[root@iZ2zeg11g0cdei5171kqskZ 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 -y install libaio-devel
3、
[root@iZ2zeg11g0cdei5171kqskZ mysql]# service mysqld startStarting MySQL.touch: cannot touch '/var/log/mariadb/mariadb.log': No such file or directorychmod: cannot access '/var/log/mariadb/mariadb.log': No such file or directorytouch: cannot touch '/var/log/mariadb/mariadb.log': No such file or directorychown: cannot access '/var/log/mariadb/mariadb.log': No such file or directory/usr/local/mysql//bin/mysqld_safe: line 129: /var/log/mariadb/mariadb.log: No such file or directory/usr/local/mysql//bin/mysqld_safe: line 166: /var/log/mariadb/mariadb.log: No such file or directorytouch: cannot touch '/var/log/mariadb/mariadb.log': No such file or directorychown: cannot access '/var/log/mariadb/mariadb.log': No such file or directorychmod: cannot access '/var/log/mariadb/mariadb.log': No such file or directory/usr/local/mysql//bin/mysqld_safe: line 129: /var/log/mariadb/mariadb.log: No such file or directoryThe server quit without updating PID file (/var/lib/mysql/i[FAILED]0cdei5171kqskZ.pid).
解决:(我们确实是没有/var/log/mariadb/mariadb.log 这个目录,这个是因为你没有指定他的配置文件的话,他会默认找到/etc/my.cnf 这个配置文件,因为我们修改了mysql的数据存储目录)、
rm -f /etc/my.cnf
4、
[root@iZ2zeg11g0cdei5171kqskZ mysql]# mysql -uroot -p-bash: mysql: command not found
解决:(这个是因为/usr/local/bin目录下缺失mysql导致,只需要一下方法建立软链接,即可以解决)
ln -s localbin/mysql localmysql
5、
sqlyog连接时,报1130错误,是由于没有给远程连接的用户权限问题
解决1:更改 ‘mysql’数据库‘user’表‘host’项,从‘localhost’改成‘%’。
use mysql; select 'host' from user where user='root'; update user set host = '%' where user ='root'; flush privileges;
解决2:直接授权
GRANT ALL PRIVILEGES ON *.* TO ‘root’@'%’ IDENTIFIED BY ‘youpassword’ WITH GRANT OPTION;
6、
-bash: ./scripts/mysql_install_db: /usr/bin/perl: bad interpreter: 没有那个文件或目录
解决:
yum -y install perl perl-devel
7、
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 -y install libaio-devel
8、
环境变量配置位置:
vi + /etc/profile
9.远程访问时要关闭防火墙或者打开mysql的端口,如果用的阿里云则要在服务器管理界面对端口进行设置,而不是在系统内部设置
以上是在linux上安装mysql的一些方法和注意事项,若有不足还请指正