linux安装mysql

安装mysql
  1. 下载 wget http://dev.MySQL.com/get/Downloads/MySQL-5.7/mysql-5.7.11-Linux-glibc2.5-x86_64.tar.gz
    tar -zxvf mysql-5.7.11-Linux-glibc2.5-x86_64.tar.gz
    mv mysql-5.7.11 /data/soft/mysql-3306
    cd mysql-3306
    mkdir data,mkdir tmp

  2. 创建mysql用户组及其用户
    groupadd mysql
    useradd -r -g mysql mysql
    chown -R mysql:mysql ./ (mysql安装目录下操作)

  3. cp -a ./support-files/my-default.cnf /etc/my.cnf (选择y)
    修改: vim /etc/my.cnf
    添加:
    basedir = /data/soft/mysql-3306
    datadir = /data/soft/mysql-3306/data
    port = 3306
    socket = /tmp/mysql.sock
    character-set-server = utf8
    user=mysql
    注:这种方式只支持单例存在不能实现同个服务器安装多个实例

  4. 初始化数据
    bin/mysqld --initialize --user=mysql --basedir=/data/soft/mysql-3306 --datadir=/data/soft/mysql-3306/data
    #bin/mysqld --defaults-file=/data/soft/mysql-3306/my.cnf --initialize --user=mysql --basedir=/data/soft/mysql-3306 --datadir=/data/soft/mysql-3306/data

  5. support-files/mysql.server start 启动mysql

  6. bin/mysql -u用户名 -p 进入mysql

重置密码
  1. stop mysql 服务

  2. 在/etc/my.cnf添加skip-grant-tables

  3. 启动mysql服务此时进入无密码状态

  4. 进入mysql update user set password=password(“输入新的密码”) where user=“root”;
    (5.7版本为 update user set authentication_string=password(“输入新的密码”) where user=“root”)

本地链接虚拟机mysql
  1. update user set host = ‘%’ where user = ‘root’;
创建一个用户
  1. create user ‘king’ identified by ‘king’;

  2. GRANT ALL PRIVILEGES ON . TO ‘root’@’%’ IDENTIFIED BY ‘youpassword’ WITH GRANT OPTION;(授权)

You must reset your password using ALTER USER statement before executing this statement异常
  1. 解决:
    SET PASSWORD = PASSWORD(‘root’);
    ALTER USER ‘root’@‘localhost’ PASSWORD EXPIRE NEVER;
    flush privileges;
linux The server quit without updating PID file异常
  1. 解决
    vim my.cnf
    tmpdir = /data/soft/mysql-3306/tmp
    保存
The server quit without updating PID file (/data/soft/mysql-3306/data/bogon.pid)异常
  1. 解决(先检查是否是权限问题,查看当前是否授权为mysql)
    注释sql_mode
Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ (2)
  1. 临时解决方案:
    #bin/mysql --socket=/data/soft/mysql-3307/tmp/mysql-3307.sock -uroot -p
    bin/mysql --socket=/data/soft/mysql-3306/tmp/mysql3306.sock -uroot -p
mysql初始化时异常:bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
  1. 解决:yum install -y libaio

####l## inux放开远程访问mysql 3306端口

  1. vim /etc/sysconfig/iptables

  2. -A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT(注意:增加的开放3306端口的语句一定要在icmp-host-prohibited之前)

  3. service iptables restart

实现同台服务安装多个mysql实例

注:安装多例一定要删/etc/my.cnf文件

  1. 完成以上操作 vim /data/soft/mysql-3306/support-files/mysql.server
    basedir=/data/soft/mysql-3306
    datadir=/data/soft/mysql-3306/data
    保存退出

  2. 删除/etc/my.cnf ,将这个配置文件放在安装目录下这样系统就会查找该安装目录下my.cnf配置文件

  3. 配置不同的:
    basedir = /data/soft/mysql-3306
    datadir = /data/soft/mysql-3306/data
    port = 3306
    socket = /tmp/mysql.sock

  4. 启动检测

解决远程连接mysql速度慢问题
  1. 在my.cnf 添加skip-name-resolve(禁用dns解析)

你可能感兴趣的:(Linux)