---
title: "mysql在liunx下的安装手册"
author: "bjameng"
date: "2015-04-27T20:10:55Z"
tags: []
categories: ["数据库"]
slug: "mysql-liunx"
draft: false
lastmod: "2015-04-27T20:14:56Z"
id: 2206566
url: "https://bjameng.iteye.com/blog/2206566"
---

01. 安装准备
    
    ```
      cd /opt
      mkdir mysql
      
      mv mysql-5.6.23-linux-glibc2.5-x86_64.tar.gz  ./mysql
      cd mysql
      tar zxvf mysql-5.6.23-linux-glibc2.5-x86_64.tar.gz
      cd mysql-5.6.23-linux-glibc2.5-x86_64
      ln -s /opt/mysql/mysql-5.6.23-linux-glibc2.5-x86_64 /usr/local/mysql
      cd /usr/local/mysql
      groupadd mysql
      useradd mysql -d /home/mysql -g mysql
    ```
02. 改变目录所有者
    
    ```
    chown -R mysql：mysql /usr/local/mysql
    ```
03. 初始化数据库
    
    ```
    cd /usr/local/mysql/scripts
    ./mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
    ```
04. 注册为服务
    
    ```
    cd /usr/local/mysql/support-files
    cp mysql.server /etc/rc.d/init.d/mysql
    ```
05. 使用默认配置文件
    
    ```
    cp my-default.cnf /etc/my.cnf
    ```
06. 让chkconfig管理mysql服务
    
    ```
    chkconfig --add mysql
    ```
07. 开机启动
    
    ```
    chkconfig mysql on
    ```
08. 修改mysql的my.cnf文件，用安装包中的my.cnf覆盖/etc/my.cnf
09. 将mysql的bin加入到path中
    
    ```
    vi /etc/profile
    #加入以下内容
    PATH=/usr/local/mysql/bin:$PATH
    export PATH
    #退出vi，执行  
    source /etc/profile
    ```
10. 启动MySQL服务
    
    ```
    service mysql start
    ```
11. 配置用户密码和远程访问权限
    
    ```
    mysql -uroot  
    SET PASSWORD = PASSWORD('123456');
    GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
    ```
12. 常用操作：
    
    ```
    启动mysql
    service mysql start
    停止mysql
    service mysql stop
    登录mysq:
    mysql -uroot -p 123456
    ```
13. 安装下载地址
    
    ```
    http://pan.baidu.com/s/1bnfeC8Z
    nb6h
    ```