CentOS 7 安装 mysql-5.7.14

在centos7上安装 路上遇过各种坑 把在centos7正确安装mysql-5.7.14分享一下

1. CentOs7 默认的数据库为MariaDB,先卸载MariaDB,否则安装mysql,引起冲突

rpm -qa  mariadb
rpm -e --nodeps  mariadb

2. 准备好工作环境 mkdir /application #此目录用来存放需要另外存放的应用程序安装目录

3. 创建mysql用户组与用户,并下载安装包

groupadd mysql
useradd -g mysql  -s /sbin/nologin  -M mysql 

id mysql
uid=1001(mysql) gid=1001(mysql) groups=1001(mysql)

PS.如果已经存在提示错误了  可以先删除

cd /application  下载安装包,
我这里安装的是,mysql-5.7.16.tar.gz
wget -c http://192.168.42.26/install_package/down/mysql-5.7.16.tar.gz

4. 解压并安装mysql

tar xf mysql-5.7.16.tar.gz 
ls
mysql-5.7.16-linux-glibc2.5-x86_64  mysql-5.7.16.tar.gz  
mv mysql-5.7.16-linux-glibc2.5-x86_64  mysql-5.7.16  


cd mysql 
[root@test mysql]# ls
bin  COPYING  docs  include  lib  man  mysql  README  share  support-files

我要把整个mysql都安装在/application目录里,下面是初始化mysql mysql5.7之前使用./bin/mysql_install_db –user=mysql –basedir=[install dir] –datadir=[data dir] 命令,但是 5.7以后已经放弃mysql_install_db,使用新的mysqld

[root@test mysql-5.7.16]#  ./bin/mysqld --user=mysql --basedir=/application/mysql-5.7.16/ --datadir=/application/mysql-5.7.16/data  --initialize
2017-05-07T02:11:06.891174Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-05-07T02:11:09.101667Z 0 [Warning] InnoDB: New log files created, LSN=45790
2017-05-07T02:11:09.572053Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2017-05-07T02:11:09.795916Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 6fc38e6f-32ca-11e7-9717-000c29c8721f.
2017-05-07T02:11:09.812070Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2017-05-07T02:11:09.827010Z 1 [Note] A temporary password is generated for root@localhost: iRctOTz9sr--

特别要注意最后的密码,是进入mysql的密码

PS.如果你的data文件有内容 会报

[ERROR] --initialize specified but the data directory has files in it. Aborting.

这个错误 正确的是把data文件清空 rm -rf *

mv /etc/my.cnf /etc/my.cnf.back.old
cd support-files/ 
cp my-default.cnf /etc/my.cnf
cp mysql.server  /etc/init.d/mysqld

[root@test application]# ln -s mysql-5.7.16 mysql
[root@test application]# ls
mysql  mysql-5.7.16  mysql-5.7.16.tar.gz  svndata  svnpasswd


[root@test support-files]# service mysqld start
/etc/init.d/mysqld: line 251: my_print_defaults: command not found
/etc/init.d/mysqld: line 271: cd: /usr/local/mysql: No such file or directory
Starting MySQL ERROR! Couldn't find MySQL server (/usr/local/mysql/bin/mysqld_safe)

因为默认的目录是/usr/local/mysql 我们换了别的目录 我们修改 vim /etc/my.cnf 

basedir=/application/mysql
datadir=/application/mysql/data
整体配置如下:
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.

[mysqld]

# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M

# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin

# These are commonly set, remove the # and set as required.
basedir = /application/mysql ######
datadir = /application/mysql/data ###
port = 3306 ###
# server_id = .....
socket =/var/lib/mysql/mysql.sock ###


# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M 

character_set_server=utf8 ###
init_connect='SET NAMES utf8' ###

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES


[client]
default-character-set=utf8
socket =/var/lib/mysql/mysql.sock

进行修改成现在的目录 之后 ESC , :号后wq回车 保存退出

5. 启动MySQL

[root@test application]# service mysqld start
Starting MySQL.... SUCCESS!

6.加入开机自启动

[root@test application]# systemctl is-enabled mysqld
mysqld.service is not a native service, redirecting to /sbin/chkconfig.
Executing /sbin/chkconfig mysqld --level=5
disabled

systemctl enable  mysqld


[root@test application]# systemctl is-enabled mysqld
mysqld.service is not a native service, redirecting to /sbin/chkconfig.
Executing /sbin/chkconfig mysqld --level=5
enabled

7. 添加环境变量vim /etc/profile.d/mysql.d

export  PATH=$PATH:/application/mysql/bin

logout  退出重新登录

8.更改msyql密码

[root@test ~]# mysql -u root -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.

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

mysql> use mysql 
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

执行任何命令都提示要更改密码

set password for 'root'@'localhost'=password('root'); ##输入这条命令即可

我们也可以通过mysqladmin来改密码 mysqladmin -u root -h localhost password ‘root’ -p ##按照提示操作即可,需要输入旧密码

重启mysql

9.如果我们想直接通过mysql命令进入mysql,又必须需要密码,怎么办,我们可以这样做,在root家目录创建 隐藏文件.my.cnf,编辑如下,运行mysql命令即可

[client]
default-character-set=utf8
socket =/var/lib/mysql/mysql.sock
user=root
host=localhost
password=root

运行mysql命令,直接进入

[root@test ~]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.16 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>

至此,mysql的安装已经完成

原创文章,作者:srayban,如若转载,请注明出处:http://www.178linux.com/74880

(2)
sraybansrayban
上一篇 2017-05-07
下一篇 2017-05-07

相关推荐

  • N26-第二周作业-邢岩(1)

     马哥门徒-N26-邢岩   度过了一个愉快的春节,又到了上班的时候了!我的Linux基础学习也进行到了疯狂记命令的阶段,痛并快乐着!那就让我来说一下Linux上的文件管理类命令都有哪些吧。   Linux的文件相关命令还是蛮多的,我不妨简单的总结一下,归结为6类常用的命令: 1、目录切换类命令   pwd命令:显示工…

    Linux干货 2017-02-10
  • Linux基础小模块

    1.基础知识小块:shell 由shell程序的自带命令:即为内置命令(builtin) 独立的可执行程序文件、文件名 :即为外部命令  [root@localhost~]#ls      ~用户当前所在目录  #:命令提示符(管理员帐号root)  $:普通用户   &nbsp…

    Linux干货 2016-08-10
  • 马哥教育网络班21期+第11周课程练习

    1、请描述一次完整的加密通讯过程,结合图示最佳。 Bob先利用单向加密算法提取当前数据的指纹(特征码),再用自己的私钥加密数据指纹并附加于数据尾部,然后利用对称加密将整个文件加密,之后用对方的公钥加密对称加密密钥附加于尾部。 Alice收到数据后,先用自己的私钥解密,得到对称加密密钥,之后用对称加密密钥解密,然后用Bob的公钥解密得到数据指纹,并且验证了Bo…

    Linux干货 2016-09-26
  • 个人思想的转变及对学习的态度

    了解linux已经一年多了,但实际上学习的次数并不多。我是在部队的时候通过网络了解到linux,刚开始接触的是乌班图系统,感觉这个系统美化比较漂亮,就安装在虚拟机里进行各种操作,但是对命令是一窍不通的,都是通过百度粘贴复制各种命令,在复制的是同时我也感觉到头大,这个系统的输入、输出怎么都是字母出现在屏幕上,顿时就感到兴趣失去了一大半,再加上自己英语也不好,就…

    Linux干货 2018-03-26
  • 第四周-grep正则表达式简单应用

    复制/etc/skel目录为/home/tuser1,要求/home/tuser1及其内部文件的属组和其它用户均没有任何访问权限。 cp -r /etc/skel /home/tuser1 && chmod 700 -R /home/tuser1 编辑/etc/g…

    Linux干货 2016-08-02
  • httpd协议配置进阶

    目录 虚拟主机配置 status状态页面 curl命令 mod_deflate模块 https配置 httpd自带应用程序 虚拟主机配置 有三种实现方案:    基于IP:        为每个虚拟主机准备至少一个IP地址    基于端口:     &nbsp…

    Linux干货 2016-10-31