如何在Linux安装mysql5.6.3的具体步骤

  1. MySQL官网下载mysql编译好的二进制安装包
    在下载页面Select Platform:选项选择Linux-generic
    然后把页面拉到底部,64位系统下载Linux - Generic (glibc 2.5) (x86, 64-bit)
    下载后文件名:mysql-5.6.33-linux-glibc2.5-x86_64.tar.gz
  2. 解压64位安装包:
    进入安装包所在目录
    执行命令:tar xzvfmysql-5.6.33-linux-glibc2.5-x86_64.tar.gz
  3. 复制解压后的mysql目录到系统的本地软件目录:
    执行命令:cp mysql-5.6.33-linux-glibc2.5-x86_64/usr/local/mysql -r
    注意:目录结尾不要加/
  4. 添加系统mysql组和mysql用户:
    执行命令:groupadd mysql和useradd -r -g mysql mysql
  5. 安装数据库:
    进入安装mysql软件目录:
    执行命令 :cd/usr/local/mysql
    修改当前目录拥有者为mysql用户:
    执行命令:chown-R mysql:mysql ./
    安装数据库:
    执行命令:./scripts/mysql_install_db --user=mysql
    修改当前目录拥有者为root用户:
    执行命令:chown-R root:root ./
    修改当前data目录拥有者为mysql用户:
    执行命令:chown -R mysql:mysql data
    到此数据库安装完毕
  6. 启动mysql服务和添加开机启动mysql服务:
    添加开机启动:
    执行命令:cp support-files/mysql.server /etc/init.d/mysql
    把启动脚本放到开机初始化目录
    chmod +x /etc/init.d/mysql 赋予可执行权限
    chkconfig --add mysql 添加服务
    chkconfig --list 显示服务列表
    如果看到mysql的服务,并且3,4,5都是on的话则成功,如果是off
    则键入:chkconfig --level 345 mysql on
    启动mysql服务:
    执行命令:service mysql start
    执行命令:ps -ef|grep mysql
    看到mysql服务说明启动成功。
  7. 修改mysqlroot用户密码,root初始密码为空的:
    执行命令:./bin/mysqladmin -u rootpassword '密码'
    如果报错:
    /usr/bin/mysqladmin: connect toserver at ‘localhost’ failed
    error: ‘Can’t connect to local MySQL server through socket’/var/lib/mysql/mysql.sock’ (2)’
    Check that mysqld is running and that the socket: '/var/lib/mysql/mysql.sock’exists!

    (1)先停止服务:service mysql stop
    (2)修改/etc/my.conf:
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
If there is not currently asection called [client], add one at the bottom of the file and copy the socket=line under the [mysqld] section such as:
[client]
socket=/var/lib/mysql/mysql.sock

(3)执行:/usr/local/mysql/bin/mysqld_safe& service mysql start
(4)无密码root帐号登陆
/usr/bin/mysql -uroot -p
【注释,在下面的要求你输入密码的时候,你不用管,直接回车键一敲就过去了】
Enter password:
Welcome to the MySQL monitor. Commandsend with ; or \g.
…………
Type ‘help;’ or ‘\h’ for help.Type ‘\c’ to clear the current input statement.
mysql> use mysql;

Database changed
(5) 手动update修改密码

mysql> update user setpassword=password("新密码") where user='root' andhost='localhost';
Query OK, 1 row affected (0.00sec)
Rows matched: 1 Changed: 1 Warnings:0
mysql> flush privileges;
Query OK, 0 rows affected (0.00sec)
mysql> quit
Bye

8.正常重新启动mysql服务登录 mysql -uroot -p
9.把mysql客户端放到默认路径:

ln -s/usr/local/mysql/bin/mysql /usr/local/bin/mysql

注意:建议使用软链过去,不要直接包文件复制,便于系统安装多个版本的mysql

你可能感兴趣的:(Linux)