mysql在linux下的安装
可参考地址:http://www.jb51.net/article/123625.htm
CentOS 开启远程端口访问:http://www.cnblogs.com/chen-lhx/p/8411338.html
1、下载
下载地址: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/mysql
3、添加用户组和用户
#添加用户组 groupadd mysql #添加用户mysql 到用户组mysql useradd -g mysql mysql
4、安装
cd /usr/local/mysql/ mkdir ./data/mysql chown -R mysql:mysql ./ chmod 755 /etc/init.d/mysqld #编译安装并初始化mysql,并记住临时密码 ./bin/mysqld --initialize --user=mysql --datadir=/usr/local/mysql/data/mysql 当时安装的临时密码为:root@localhost:3?2YBeSg:Nte #创建日志文件目录 mkdir -p /data/mysql/log/mariadb/ cd /data/mysql/log/mariadb/ touch mariadb.log chmod -R 775 mariadb.log chown -R mysql:mysql mariadb.log chown -R mysql:mysql /data/mysql 11、启动mysql服务 support-files/mysql.server start 12、登录msyql,输入密码(密码为第9步骤的初始化密码) mysql -u root -p 13、 修改密码为“123456” msql>alter user 'root'@'localhost' identified by '123456'; mysql>use mysql; msyql>update user set user.Host='%' where user.User='root'; mysql>flush privileges; mysql>quit 14、修改/etc/my.cnf文件 # instructions in http://fedoraproject.org/wiki/Systemd socket=/tmp/mysql.sock [mysqld] datadir=/data/mysql/data socket=/tmp/mysql.sock max_connections=1000 # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 # Settings user and group are ignored when systemd is used. # If you need to run mysqld under a different user or group, # customize your systemd unit file for mariadb according to the # instructions in http://fedoraproject.org/wiki/Systemd [mysqld_safe] log-error=/data/mysql/log/mariadb/mariadb.log pid-file=/data/mysql/run/mariadb/mariadb.pid # # include all files from the config directory # !includedir /etc/my.cnf.d #加入环境变量,编辑 /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、错误
5.1 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;
5.2 安装时的一些错误
-bash: ./scripts/mysql_install_db: /usr/bin/perl: bad interpreter: 没有那个文件或目录
解决: yum -y install perl perl-devel
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
6、其他
6.1 配置环境变量
vi + /etc/profile
export PATH=....:/usr/local/mysql/bin