转自:http://forrest-lv.iteye.com/blog/2260703

安装前,需要检查是否已经有mysql服务进程,是否已经装过mysql;  这点很重要,我之前安装CentOS的同时,安装了mysql相关的东东,导致后面新安装mysql时,安装、启动时报了一堆的错。

例如:

Ignoring user change to 'laolv' because the user was set to 'mysql' earlier on the command line

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

mysql Unknown error 1045

参考网址

http://www.cnblogs.com/kreo/p/4392090.html

http://blog.csdn.net/chenggong2dm/article/details/6568862

http://tieba.baidu.com/p/3881791613

http://bbs.chinaunix.net/thread-3967681-1-1.html

一、卸载

卸载前关闭MySQL服务:

[laolv@centos65 Desktop]$ ps -ef | grep mysql

[laolv@centos65 Desktop]$ chkconfig --list | grep -i mysql

因为没有将mysql做成服务,那么查出进程号,直接

kill -9 pid

查找机器是否安装mysql,如果安装过则卸载

[root@centos65 ~]# rpm -qa | grep -i mysql

[root@centos65 ~]# rpm -ev mysql-libs-5.1.-.el6.x86_64 --force

rpm: only installation, upgrading, rmsource and rmspec may be forced

[root@centos65 ~]# rpm -ev mysql-libs-5.1.-.el6.x86_64 --nodeps

warning: /etc/my.cnf saved as /etc/my.cnf.rpmsave

删除mysql用户

[root@DB-Server ~]# id mysql 

uid=(mysql) gid=(mysql) groups=(mysql) context=root:system_r:unconfined_t:SystemLow-SystemHigh 

[root@DB-Server ~]# userdel mysql

删除MySQL对应的文件夹:

[root@centos65 ~]# find / -name mysql

/home/mysql

/var/spool/mail/mysql

/var/lib/mysql

/var/lib/mysql/mysql

/mnt/hgfs/sharefiles/apache-hive-1.3.-SNAPSHOT-bin/scripts/metastore/upgrade/mysql

/opt/hive/apache-hive-1.3.-SNAPSHOT-bin/scripts/metastore/upgrade/mysql

/opt/softwares/mysql-5.7.-linux-glibc2.-x86_64/include/mysql

/opt/softwares/mysql-5.7.-linux-glibc2.-x86_64/bin/mysql

[root@centos65 ~]# rm -rf /var/lib/mysql/

[root@centos65 ~]# rm -rf /home/mysql/

[root@centos65 ~]# rm -rf /var/spool/mail/mysql

重启操作系统

二、安装

一般安装都是先创建 用户:组 mysql:mysql ,例如网址一

我这儿使用已经存在的用户:组 laolv:laolv

需要注意:

glibc版本的Mysql,不是编译版的,是直接编译好的,相当于windows的绿色版

CentOS默认yum源已经没有mysql-server了.而用mariadb代替,而2个数据库冲突,所以要安装mysql,要先卸载mariadb

我的机器上是没有mariadb的

[root@centos65 ~]# find / -name mariadb

[root@centos65 ~]# ps -ef | grep mariadb

root           : pts/    :: grep mariadb

[root@centos65 ~]# rpm -qa | grep -i mariadb

[root@centos65 ~]# 

[laolv@centos65 softwares]$ mv mysql-5.7.-linux-glibc2.-x86_64 mysql_5_7_9

[laolv@centos65 softwares]$ cd mysql_5_7_9

需要注意:

参考http://tieba.baidu.com/p/3881791613

mysql_install_db 已经不再推荐使用了,建议改成 mysqld --initialize 完成实例初始化。

改成 mysqld --initialize 后,如果 datadir 指向的目标目录下已经有数据文件,则会有类似提示:

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

另外,在初始化时如果加上 --initialize-insecure ,则会创建空密码的 root@localhost 账号,否则会创建带密码的 root@localhost 账号,密码直接写在 log-error 日志文件中(在5.6版本中是放在 ~/.mysql_secret 文件里,更加隐蔽,不熟悉的话可能会无所适从)

1.安装Mysql/初始化mysql数据库

[laolv@centos65 mysql_5_7_9]$ mkdir data

[laolv@centos65 mysql_5_7_9]$ ./bin/mysqld --user=laolv --basedir=/opt/softwares/mysql_5_7_9 --datadir=/opt/softwares/mysql_5_7_9/data  --initialize-insecure

--30T17::.346374Z  [Warning] Changed limits: max_open_files:  (requested )

--30T17::.359032Z  [Warning] Changed limits: table_open_cache:  (requested )

--30T17::.359397Z  [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).

--30T17::.788602Z  [Warning] InnoDB: New log files created, LSN=

--30T17::.859671Z  [Warning] InnoDB: Creating foreign key constraint system tables.

--30T17::.899396Z  [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: f0ac2cdd--11e5--000c292ec6d6.

--30T17::.901991Z  [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.

--30T17::.903051Z  [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.

[laolv@centos65 mysql_5_7_9]$ 

2.开启mysql

(

注意 bin/mysqld_safe --user=laolv &

我没有在后面带& , &表示在后台运行,ctrl-c结束不掉进程的,需要kill -9 pid 结束进程的

)

[laolv@centos65 mysql_5_7_9]$ bin/mysqld_safe --user=laolv

 :: mysqld_safe Logging to '/opt/softwares/mysql_5_7_9/data/centos65.err'.

 :: mysqld_safe Starting mysqld daemon with databases from /opt/softwares/mysql_5_7_9/data

至此,mysql安装成功。

因为mysq处在运行状态,不要ctrl-c,再开一个ssh窗口,进行登录验证之类的..

[laolv@centos65 Desktop]$ ps -ef | grep mysql

laolv          : pts/    :: /bin/sh bin/mysqld_safe --user=laolv

laolv          : pts/    :: /opt/softwares/mysql_5_7_9/bin/mysqld --basedir=/opt/softwares/mysql_5_7_9 --datadir=/opt/softwares/mysql_5_7_9/data --plugin-dir=/opt/softwares/mysql_5_7_9/lib/plugin --user=laolv --log-error=/opt/softwares/mysql_5_7_9/data/centos65.err --pid-file=/opt/softwares/mysql_5_7_9/data/centos65.pid

laolv          : pts/    :: grep mysql

[laolv@centos65 Desktop]$ lsof -i:

COMMAND  PID  USER   FD   TYPE DEVICE SIZE/OFF NODE NAME

mysqld   laolv   20u  IPv6        0t0  TCP *:mysql (LISTEN)

[laolv@centos65 Desktop]$ 

3.为mysql的root用户添加密码

[laolv@centos65 Desktop]$ vi ~/.bash_profile 

MYSQL_HOME=/opt/softwares/mysql_5_7_9
export MYSQL_HOME
PATH=$MYSQL_HOME/bin:$HIVE_HOME/bin:$HOME/bin:$PROTOBUF_HOME/bin:$JAVA_HOME/bin:$MAVEN_HOME/bin:$ANT_HOME/bin:$HADOOP_HOME/bin:$HADOOP_HOME/sbin:$CMAKE_HOME/bin:$PATH
export PATH [laolv@centos65 Desktop]$ su - laolv
密码: [laolv@centos65 ~]$ which mysql
/opt/softwares/mysql_5_7_9/bin/mysql
[laolv@centos65 ~]$ mysql -uroot -p
Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is Server version: 5.7. MySQL Community Server (GPL) Copyright (c) , , 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> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | +--------------------+ rows in set (0.03 sec) mysql> set password = password('forrest'); Query OK, rows affected, warning (0.01 sec) mysql> exit Bye [laolv@centos65 ~]$ mysql -uroot -p Enter password: 此时需要输入密码了 mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | +--------------------+ rows in set (0.00 sec) mysql> use mysql Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql> show tables; +---------------------------+ | Tables_in_mysql | +---------------------------+ | columns_priv | | db | | engine_cost |

4. 关闭mysql

#关闭mysql

mysqladmin shutdown

#或

m

mysqladmin -uroot -p shutdown

mysql> exit

Bye

[laolv@centos65 ~]$ mysqladmin -uroot -p shutdown

Enter password:

[laolv@centos65 ~]$ ps -ef | grep mysql

laolv    11656  9533  0 17:44 pts/1    00:00:00 grep mysql

[laolv@centos65 ~]$

5. 今后开启mysql

不再需要初始化了,直接

[laolv@centos65 mysql_5_7_9]$ bin/mysqld_safe --user=laolv

151130 17:46:41 mysqld_safe Logging to '/opt/softwares/mysql_5_7_9/data/centos65.err'.

151130 17:46:41 mysqld_safe Starting mysqld daemon with databases from /opt/softwares/mysql_5_7_9/data

另开终端

[laolv@centos65 ~]$ ps -ef | grep mysql

laolv    11815  5342  0 17:46 pts/0    00:00:00 /bin/sh bin/mysqld_safe --user=laolv

laolv    11895 11815  6 17:46 pts/0    00:00:00 /opt/softwares/mysql_5_7_9/bin/mysqld --basedir=/opt/softwares/mysql_5_7_9 --datadir=/opt/softwares/mysql_5_7_9/data --plugin-dir=/opt/softwares/mysql_5_7_9/lib/plugin --user=laolv --log-error=/opt/softwares/mysql_5_7_9/data/centos65.err --pid-file=/opt/softwares/mysql_5_7_9/data/centos65.pid

laolv    11932  9533  0 17:46 pts/1    00:00:00 grep mysql

[laolv@centos65 ~]$ mysql -uroot -p

Enter password:

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

Your MySQL connection id is 2

Server version: 5.7.9 MySQL Community Server (GPL)

Copyright (c) 2000, 2015, 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> show database;

CentOS6.5 安装mysql-5.7.9的更多相关文章

  1. Centos6.5 安装MYSQL 5.5 -5.6.-5.7 一键yum快速安装 ,初始配置

    Centos6.5 安装MYSQL 5.5 ---5.6---5.7 一键yum快速安装 ,初始配置 第一步:安装mysql-5.5---- 5.6 ---- 5.7的yum源 [root@sv03 ...

  2. Mysql系列三:Centos6下安装Mysql和Mysql主从复制的搭建

    一.Centos6下安装Mysql 检测下系统有没有自带的mysql:yum list installed | grep mysql, 如果已经有的话执行命令yum -y remove mysql-l ...

  3. 【转】CentOS6下安装mysql后,重置root密码方法

    本文转自:CentOS6下安装mysql后,重置root密码方法 centos下安装mysql,居然不知道root用户密码,本想重装,不过还是先度娘了一些,发现这篇文章,刚好解决我的燃眉之急,太赞了. ...

  4. CentOS6.9安装MySQL(编译安装、二进制安装)

    目录 CentOS6.9安装MySQL Linux安装MySQL的4种方式: 1. 二进制方式 特点:不需要安装,解压即可使用,不能定制功能 2. 编译安装 特点:可定制,安装慢 5.5之前: ./c ...

  5. 在Centos6.5安装MySQL

    在阐述安装过程之前一定要再写一句,Centos7上安装MySQL是默认安装的MariaDB,因为在Centos7中用MariaDB代替了mysql数据库. linux安装软件很简单,有的时候只有一句话 ...

  6. Centos6.7安装mysql 5.6简单教程

    今天项目经理让我给服务器配一下mysql,以前配置mysql的时候,感觉好麻烦,前几天也帮朋友配置来着,今天装的时候一直报错,百度也没搞明白,所以打算换种方法装mysql,无意中发现了还有这种操作,容 ...

  7. CentOS6.5安装mysql以及常见问题的解决

    前言 最近在学习Linux系统,今天在安装MySQL数据库时出现很多问题,花费了两个小时终于解决,故记录下来以供大家参考.(本人目前还在学习阶段,下面写到的是自己结合网上查到的资料以及各位前辈给出的解 ...

  8. 36. CentOS-6.3安装Mysql集群

    安装要求 安装环境:CentOS-6.3安装方式:源码编译安装 软件名称:mysql-cluster-gpl-7.2.6-linux2.6-x86_64.tar.gz下载地址:http://mysql ...

  9. centos6.5 安装mysql

    在centos6.5上通过yum安装mysql: 1. yum list |grep mysql   (查看版本) 2.安装mysql yum install -y mysql-server mysq ...

  10. 阿里云服务器CentOS6.9安装Mysql

    上篇讲了CentOS6.9安装tomcat,这篇来讲mysql的安装 1.查看CentOS是否安装了MySQL yum list installed | grep mysql //查看CentOS是否 ...

随机推荐

  1. 安装 bochs

    sudo apt-get install bochs 以后接着安装bochs-x

  2. 探索解析微服务下的RabbitMQ

    概览 本文主要介绍如何使用RabbitMQ消息代理来实现分布式系统之间的通信,从而促进微服务的松耦合. RabbitMQ,也被称为开源消息代理,它支持多种消息协议,并且可以部署在分布式系统上.它轻量级 ...

  3. zoj3261变形并查集

    需要变形的并查集,这题错了好久,一直没a掉,终于在重写第三次的时候a了 先保存数据,把不需要拆分的边合并,逆向计算,需要拆分时就合并,之前不知道为啥写搓了,tle好久 #include<map& ...

  4. UVA-11383 Golden Tiger Claw (KM算法)

    题目大意:一张可行二分图的权值以邻接矩阵的形式给了出来,现在要找每一个节点的可行顶标,使顶标和最小. 题目分析:直接用KM算法,结束后顶标之和最小...模板题. 代码如下: # include< ...

  5. 理解 Ruby Symbol (Ruby中的冒号)

    http://blog.csdn.net/besfanfei/article/details/7966850 一直不明白:的作用 直到看到这篇文章 豁然开朗 处理符号相比字符串,占用更少的资源

  6. 001PHP文件处理——文件处理disk_total_space disk_free_space basename dirname file_exists filetype

    <?php /** * 文件处理disk_total_space disk_free_space basename dirname file_exists filetype */ //disk_ ...

  7. BOM之其他浏览器对象的使用

    body, table{font-family: 微软雅黑; font-size: 10pt} table{border-collapse: collapse; border: solid gray; ...

  8. 彻底弄懂jQuery事件原理一

    jQuery为我们提供了一个非常丰富好用的事件API,相对于浏览器自身的事件接口,jQuery有以下特点: 1. 对浏览器进行了兼容性处理,用户使用不需要考虑浏览器兼容性问题 2. 事件数据是保持在内 ...

  9. Jenkins插件开发(四)-- 插件发布

    上一篇blog介绍了插件开发中要注意的一些问题, 我们再来介绍插件开发完成后,如何上传到jenkins的插件中心(这里假设你的代码是放在github上的,使用svn或其他版本管理工具的请参考其他文章) ...

  10. C#读写 AB PLC 直接通过节点来读写数据 读写 AllenBradley PLC

    本文将使用一个Github开源的组件库技术来读写AB PLC,使用的是基于以太网的实现,不需要额外的组件,读取操作只要放到后台线程就不会卡死线程,本组件支持超级方便的高性能读写操作 官网:http:/ ...