linux 命令行下载mysql

[root@iz2ze4fw14evhms6nzz6t0z home]# cd /usr/local/src
[root@iz2ze4fw14evhms6nzz6t0z src]#  wget -c http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.16-linux-glibc2.5-x86_64.tar.gz
检查mysql组和用户是否存在,如无创建
[root@iz2ze4fw14evhms6nzz6t0z src]# cat /etc/group | grep mysql
mysql:x:1002:
[root@iz2ze4fw14evhms6nzz6t0z src]#  cat /etc/passwd | grep mysql
mysql:x:1002:1002::/home/mysql:/sbin/nologin
以上为存在的情况,如无,执行添加命令:
[root@VM_112_250_centos src]# groupadd mysql
[root@VM_112_250_centos src]# useradd -r -g mysql mysql
[root@iz2ze4fw14evhms6nzz6t0z src]# tar -xzvf mysql-5.7.16-linux-glibc2.5-x86_64.tar.gz
创建mysql目录
[root@iz2ze4fw14evhms6nzz6t0z src]# mkdir /usr/local/mysql
创建mysql数据目录
[root@iz2ze4fw14evhms6nzz6t0z src]# mkdir /usr/local/mysql/data
把解压后的所有文件移动到/usr/local/mysql目录下
[root@VM_112_250_centos src]# mv mysql-5.7.16-linux-glibc2.5-x86_64/* /usr/local/mysql
切换到mysql目录,然后就可以看到mysql目录下就有了这些内容

[root@VM_112_250_centos mysql]# dir

COPYING README bin data docs include lib man share support-files

更改mysql目录所属的用户(用户为mysql)

[root@VM_112_250_centos mysql]# chown -R mysql ../mysql/ //这里已经切到mysql目录了,所以添加了../

更改mysql目录所属组(组为mysql)

[root@VM_112_250_centos mysql]# chgrp -R mysql ../mysql/

#-R是递归的意思,就是把mysql目录下的全部文件和子目录都设置为mysql用户和mysql组。

#上面的做法是为了把mysql降权,以限定只能访问属于mysql用户的文件。

4. 安装及初始化数据库(创建系统数据库的表)

[root@VM_112_250_centos mysql]# bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/

2016-11-17 13:07:49 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize

2016-11-17 13:08:10 [WARNING] The bootstrap log isn't empty:

2016-11-17 13:08:10 [WARNING] 2016-11-17T05:07:53.787853Z 0 [Warning] --bootstrap is deprecated. Please consider using --initialize instead

5. 配置mysql数据库

复制配置文件

[root@VM_112_250_centos mysql]# cp -a ./support-files/my-default.cnf /etc/my.cnf

[root@VM_112_250_centos mysql]# cp -a ./support-files/mysql.server  /etc/init.d/mysqld

更改配置文件信息

使用命令

vim /etc/my.cnf

打开my.cnf文件

然后按键盘I按键进入VIM的插入模式进行编辑

# These are commonly set, remove the # and set as required.

basedir = /usr/local/mysql

datadir = /usr/local/mysql/data

port = 3306

之后按ESC按键退出,:w进行保存,:q退出vim即可

加入环境变量,可以参考 linux中添加环境变量的方法

[root@VM_112_250_centos ~]# echo “PATH=/usr/local/mysql/bin:$PATH” >>/etc/profile

设置开机启动,可以参考 linux下配置mysql开机自启动

启动试一下:

[root@VM_112_250_centos init.d]# /etc/init.d/mysqld restart

ERROR! MySQL server PID file could not be found! —-因为还没启动所以会抛这个错误

Starting MySQL. SUCCESS!

// mysql的日志文件在/usr/local/mysql/data/foo.err文件中(foo为别名)

6. 初始化密码

mysql5.7会生成一个初始化密码,而在之前的版本首次登陆不需要密码。

[root@VM_112_250_centos bin]# ./mysql -uroot -p

Enter password:

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

所以这里需要初始化密码

[root@VM_112_250_centos bin]# cat /root/.mysql_secret

# Password set for user 'root@localhost' at 2016-11-17 13:07:49

Roa%ZwziC%yS

然后进行登陆

[root@VM_112_250_centos bin]# ./mysql -uroot -p

Enter password:

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

Your MySQL connection id is 3

Server version: 5.7.16

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.

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值