Mysql5.6安装

第1章 安装MySQL

1.1 进行编译下载MySQL软件

#把安装包上传到/install/目录中

-rw-r--r-- 1 root root 314149697 Apr  1 10:19 mysql-5.6.34-linux-glibc2.5-x86_64.tar.gz

1.2 解压软件程序

命令:(切换)cd /install

命令:(解压) tar xf mysql-5.6.34-linux-glibc2.5-x86_64.tar.gz

命令:(查看)ll

drwxr-xr-x 13 root root 4096 Feb 7 15:19 mysql-5.6.34-linux-glibc2.5-x86_64

-rw-r--r-- 1 root root 314149697 Mar 23 2017 m ysql-5.6.34-linux-glibc2.5-x86_64.tar.gz

1.3 将解压后的程序目录移动到/opt/目录中,创建软连接

命令:(移动)cp -r mysql-5.6.34-linux-glibc2.5-x86_64 /opt/

命令:(重命名)mv /opt/mysql-5.6.34-linux-glibc2.5-x86_64 /opt/mysql-5.6.34

命令:(创软连接)ln -s /opt/mysql-5.6.34/ /opt/mysql

命令:(查看)ll /opt/

lrwxrwxrwx 1 root root 48 Feb 6 20:18 mysql -> /opt/mysql-5.6.34-linux-glibc2.5-x86_64/

drwxr-xr-x 13 root root 4096 Feb 6 20:18 mysql-5.6.34-linux-glibc2.5-x86_64

1.4 创建数据目录管理用户

命令:(创建用户)useradd -M -s /sbin/nologin mysql

命令:(进行数据目录授权)chown -R mysql.mysql /opt/mysql/data/

1.5 初始化数据库程序

命令:(初始化)/opt/mysql/scripts/mysql_install_db --basedir=/opt/mysql --datadir=/opt/mysql/data --user=mysql

初始化参数说明:

1. 确认软件安装在哪里

2. 确认数据存放在哪里

3. 确认MySQL使用的用户谁?(/install/)

1.6 复制启动脚本,并且进行授权

命令:(复制到/etc/init.d/)cp /opt/mysql/support-files/mysql.server /etc/init.d/mysqld

命令:(进行添加执行权限)chmod +x /etc/init.d/mysqld

1.7 修改启动脚本 和 mysql命令中的路径

命令:(更改默认安装目录)sed -i 's#/usr/local/mysql#/opt/mysql#g' /opt/mysql/bin/mysqld_safe /etc/init

.d/mysqld

复制默认的配置文件

命令:(进行添加配置文件)cp /opt/mysql/support-files/my-default.cnf /etc/my.cnf

1.8 启动mysql服务并添加mysql的命令的绝对路径

命令:(开启)/etc/init.d/mysqld start

命令:(添加路径)echo "export PATH=/opt/mysql/bin:$PATH" >>/etc/profile

命令:(生效)source /etc/profile

1.9 给数据库设置一个密码

命令:/opt/mysql/bin/mysqladmin -u root  -h nginx  password '123456'

1.10 进入数据库

命令:(进入)mysql -uroot -p1234356

Warning: Using a password on the command line interface can be insecure.

Welcome to the MySQL monitor. Commands end with ; or g.

Your MySQL connection id is 16

Server version: 5.6.34 MySQL Community Server (GPL)

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

mysql>

1.11 添加mysql服务开机自启

#因为mysql的配置文件已经放到/etc/init.d/目录下了,并且经过了授权

命令:(让chkconfig管理)chkconfig --add mysqld

命令:(设置mysql开机自启)chkconfig mysqld on

原文地址:https://www.cnblogs.com/A121/p/10635264.html