liunx 环境安装mysql 5.6
mysql 5.6 下载链接 :https://dev.mysql.com/downloads/mysql/5.6.html#downloads
Select Operating System
选择 :Linux - Generic
把(mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz) 下载下来 因为我的centos7 是64位的所以下载的是64位,其他的自己看看系统
查看操作系统命令:
cat /etc/redhat-release
用putty 工具登录 liunx系统
创建mysql5.6 文件夹 (我的mysql 安装路径是这 个 /usr/local/mysql5.6)
cd /usr/local
mkdir mysql5.6
用xftp5 把下载下来的 mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz 上传到mysql5.6文件夹上面
用putty 工具 登录liunx 系统
输入命令:
cd /usr/local/mysql5.6
tar -zxvf mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz # 执行解压命令
参考目录信息:
cd ./mysql-5.6.36-linux-glibc2.5-x86_64
ll
drwxr-xr-x. 2 root root 4096 Jun 5 20:12 bin
-rw-r--r--. 1 7161 31415 17987 Mar 18 02:43 COPYING
drwxr-xr-x. 3 root root 17 Jun 5 20:11 data
drwxr-xr-x. 2 root root 52 Jun 5 20:12 docs
drwxr-xr-x. 3 root root 4096 Jun 5 20:11 include
drwxr-xr-x. 3 root root 4096 Jun 5 20:12 lib
drwxr-xr-x. 4 root root 28 Jun 5 20:11 man
drwxr-xr-x. 10 root root 4096 Jun 5 20:11 mysql-test
-rw-r--r--. 1 7161 31415 2496 Mar 18 02:43 README
drwxr-xr-x. 2 root root 29 Jun 5 20:11 scripts
drwxr-xr-x. 28 root root 4096 Jun 5 20:11 share
drwxr-xr-x. 4 root root 4096 Jun 5 20:12 sql-bench
drwxr-xr-x. 2 root root 4096 Jun 5 20:11 support-files
配置用户,目录
mkdir -p /usr/local/mysql5.6/mysql-5.6.36-linux-glibc2.5-x86_64/data
mkdir -p /usr/local/mysql5.6/mysql-5.6.36-linux-glibc2.5-x86_64/sock
mkdir -p /usr/local/mysql5.6/mysql-5.6.36-linux-glibc2.5-x86_64binlog
mkdir -p /usr/local/mysql5.6/mysql-5.6.36-linux-glibc2.5-x86_64/slowlog
mkdir -p /usr/local/mysql5.6/mysql-5.6.36-linux-glibc2.5-x86_64/errorlog
mkdir -p /usr/local/mysql5.6/mysql-5.6.36-linux-glibc2.5-x86_64/pid
groupadd mysql # 创建mysql 用户组
vi /etc/group #查看是的添加成功 按ESC 输入 :q! 不保存直接退出 或者输入(cat /etc/group)
useradd -g mysql mysql #添加mysql用户到mysql用户组里面
温馨提示:(输入 passwd 用户名 练习两次输入密码 可以给用户设置密码) 例:passwd mysql
查看用户组和用户信息:
cat /etc/passwd
chown -R mysql.mysql /usr/local/mysql5.6/mysql-5.6.36-linux-glibc2.5-x86_64
配置mysql配置文件
vi /etc/my.cnf
按 i 进入编辑模式
配置以下信息:
[mysqld]
[client]
# CLIENT #
port = 3306
socket = /usr/local/mysql5.6/mysql-5.6.36-linux-glibc2.5-x86_64/sock/mysql.sock
character-set-server = utf8
[mysqld]
# GENERAL #
port = 3306
basedir = /usr/local/mysql5.6/mysql-5.6.36-linux-glibc2.5-x86_64
socket = /usr/local/mysql5.6/mysql-5.6.36-linux-glibc2.5-x86_64/sock/mysql.sock
pid-file = /usr/local/mysql5.6/mysql-5.6.36-linux-glibc2.5-x86_64/pid/mysql.pid
# DATA STORAGE #
datadir = /usr/local/mysql5.6/mysql-5.6.36-linux-glibc2.5-x86_64/data
# BINARY LOGGING #
log-bin = /usr/local/mysql5.6/mysql-5.6.36-linux-glibc2.5-x86_64/binlog/mysql-bin
expire-logs-days = 14
sync-binlog = 1
log-slave-updates
# ERROR LOG #
log-error = /usr/local/mysql5.6/mysql-5.6.36-linux-glibc2.5-x86_64/errorlog/mysql-error.log
log-queries-not-using-indexes = 1
#开启慢日志
slow-query-log = 1
slow-query-log-file = /usr/local/mysql5.6/mysql-5.6.36-linux-glibc2.5-x86_64/slowlog/mysql-slow.log e
配置完成后 按 ESC 输入 :wq! 保存退出
初始化数据库:
cd /usr/local/mysql5.6/mysql-5.6.36-linux-glibc2.5-x86_64/scripts
./mysql_install_db --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql5.6/mysql-5.6.36-linux-glibc2.5-x86_64
--datadir=/usr/local/mysql5.6/mysql-5.6.36-linux-glibc2.5-x86_64/data/ --user=mysql
出现如下信息就是成功了: 接下来就是启动mysql(如果报错 )
OK
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/usr/local/mysql5.6/mysql-5.6.36-linux-glibc2.5-x86_64/bin/mysqladmin -u root password 'new-password'
/usr/local/mysql5.6/mysql-5.6.36-linux-glibc2.5-x86_64/bin/mysqladmin -u root -h localhost.localdomain password 'new-password'
Alternatively you can run:
/usr/local/mysql5.6/mysql-5.6.36-linux-glibc2.5-x86_64/bin/mysql_secure_installation
which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.
See the manual for more instructions.
You can start the MySQL daemon with:
cd . ; /usr/local/mysql5.6/mysql-5.6.36-linux-glibc2.5-x86_64/bin/mysqld_safe &
You can test the MySQL daemon with mysql-test-run.pl
cd mysql-test ; perl mysql-test-run.pl
Please report any problems at http://bugs.mysql.com/
The latest information about MySQL is available on the web at
http://www.mysql.com
Support MySQL by buying support/licenses at http://shop.mysql.com
WARNING: Found existing config file /usr/local/mysql5.6/mysql-5.6.36-linux-glibc2.5-x86_64/my.cnf on the system.
Because this file might be in use, it was not replaced,
but was used in bootstrap (unless you used --defaults-file)
and when you later start the server.
The new default config file was created as /usr/local/mysql5.6/mysql-5.6.36-linux-glibc2.5-x86_64/my-new.cnf,
please compare it with your file and take the changes you need.
WARNING: Default config file /etc/my.cnf exists on the system
This file will be read by default by the MySQL server
If you do not want to use this, either remove it, or use the
--defaults-file argument to mysqld_safe when starting the server
启动mysql :
/usr/local/mysql5.6/mysql-5.6.36-linux-glibc2.5-x86_64/support-files/mysql.server start
关闭mysql
killall mysqld 或者
/usr/local/mysql5.6/mysql-5.6.36-linux-glibc2.5-x86_64/support-files/mysql.server stop
chown 777 /etc/my.cnf #授予my.cnf最大权限
cd /usr/local/mysql5.6/mysql-5.6.36-linux-glibc2.5-x86_64 #进入mysql 安装目录
cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld #复制启动脚本到资源目录
chmod +x /etc/rc.d/init.d/mysqld#增加mysqld服务控制脚本执行权限
chkconfig --add mysqld#将mysqld服务加入到系统服务
chkconfig --list mysqld#检查mysqld服务是否已经生效
输出:mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
表明mysqld服务已经生效,在2、3、4、5运行级别随系统启动而自动启动,以后可以使用service命令控制mysql的启动和停止
命令为:service mysqld start和service mysqld stop
service mysqld start #启动mysqld
service mysqld stop#关闭mysqld将mysql的bin目录加入PATH环境变量,编辑
~/.bash_profile文件
vi ~/.bash_profile
按 i 进入编辑模式
在文件最后添加如下信息:
export PATH=$PATH:/usr/local/mysql5.6/mysql-5.6.36-linux-glibc2.5-x86_64/bin 注:这个mysql安装的路径,看自己的安装路径。
按ESC 输入 :wq! 保存退出
source ~/.bash_profile #立即生效配置文件
mysql -uroot -p #新安装默认是没有密码的,回车按两次就可以登录成功了
因为是第一次安装是不需要密码登录的
mysql -uroot -p
回车
提示输入密码,为空回车
update mysql.user set password=PASSWORD('12345678') where user='root';
刷新权限表,输入如下命令
flush privileges;
退出
quit