参考: http://www.2cto.com/database/201501/371451.htmlhtml
安装环境 CentOS版本:CentOS-7node
由于以前安装过,没有成功,可是有以前安装的文件,要先卸载mysql
网上找了一个卸载的过程以下:linux
a)查看系统中是否以rpm包安装的mysql:sql
[root@centos7 ~]# rpm -qa | grep -i mysql
MySQL-server-5.6.17-1.el6.i686
MySQL-client-5.6.17-1.el6.i686
b)卸载mysql
[root@centos7 ~]# rpm -e MySQL-server-5.6.17-1.el6.i686
[root@centos7 ~]# rpm -e MySQL-client-5.6.17-1.el6.i686
c)删除mysql服务
[root@centos7 ~]# chkconfig --list | grep -i mysql
[root@centos7 ~]# chkconfig --del mysql
d)删除分散mysql文件夹
[root@centos7 ~]# whereis mysql 或者 find / -name mysql数据库
mysql: /usr/lib/mysql /usr/share/mysqlwindows
清空相关mysql的全部目录以及文件
[root@centos7 ~]#rm -rf /usr/lib/mysql
[root@centos7 ~]#rm -rf /usr/share/mysql
[root@centos7 ~]#rm -rf /usr/my.cnfcentos
下载并安装 官网下载dom
1. 解压下载的zip包,会发现有如下几个rpm包:ide
MySQL-client-advanced-5.6.22-1.el7.x86_64.rpm
MySQL-devel-advanced-5.6.22-1.el7.x86_64.rpm
MySQL-embedded-advanced-5.6.22-1.el7.x86_64.rpm
MySQL-server-advanced-5.6.22-1.el7.x86_64.rpm
MySQL-shared-advanced-5.6.22-1.el7.x86_64.rpm
MySQL-shared-compat-advanced-5.6.22-1.el7.x86_64.rpm
MySQL-test-advanced-5.6.22-1.el7.x86_64.rpm
2. 卸载MariaDB(这一步没操做过)
若是直接点击rpm包安装会获得错误提示。由于CentOS的默认数据库已经再也不是MySQL了,而是MariaDB,为何呢?
MariaDB数据库管理系统是MySQL的一个分支,主要由开源社区在维护,采用GPL受权许可。开发这个分支的缘由之一是:甲骨文公司收购了MySQL后,有将MySQL闭源的潜在风险,所以社区采用分支的方式来避开这个风险。MariaDB的目的是彻底兼容MySQL,包括API和命令行,使之能轻松成为MySQL的代替品。
查看当前安装的mariadb包:
[root@centos7 ~]# rpm -qa | grep mariadb
将它们通通强制性卸载掉:
[root@centos7 ~]# rpm -e --nodeps mariadb-libs-5.5.35-3.el7.x86_64
[root@centos7 ~]# rpm -e --nodeps mariadb-5.5.35-3.el7.x86_64
[root@centos7 ~]# rpm -e --nodeps mariadb-server-5.5.35-3.el7.x86_64
3. 安装MYSQL
按顺序执行
rpm -ivh MySQL-client-advanced-5.6.22-1.el7.x86_64.rpm
rpm -ivh MySQL-devel-advanced-5.6.22-1.el7.x86_64.rpm
rpm -ivh MySQL-server-advanced-5.6.22-1.el7.x86_64.rpm
完成..
4. 启动MYSQL
[root@centos7 mysql]#service mysql start
查看MySQL运行状态:
[root@centos7 mysql]# service mysql status
SUCCESS! MySQL running (14158)
5. 默认root用户登陆MYSQL
[root@centos7 mysql]# mysql -u root -p
Enter password:
ERROR 1045 (28000):Access denied for user 'root'@'localhost' (using password: YES)
发现有有错误,而后在网上查了一下说使用下面命令修改root初始化密码:
[root@centos7 mysql]# /usr/bin/mysqladmin -u root password 'passok'
/usr/bin/mysqladmin: connect to server at'localhost' failed
error: 'Accessdenied for user 'root'@'localhost' (using password: NO)'
发现MYSQL数据库默认的root用户仍是没办法设置密码进行登陆,须要作一下操做:
重置MySQL中root用户密码及验证
仍是不行,而后在网上又找到一个重置MySQL中root用户密码及验证的方法:
(1) 中止MySQL服务
[root@centos7 mysql]# service mysql stop
Shutting down MySQL.. SUCCESS!
(2) 输入绕过密码认证命令
[root@centos7 mysql]# mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
[1] 5807
150117 22:23:31 mysqld_safe Logging to '/var/lib/mysql/bogon.err'.
150117 22:23:31 mysqld_safe Starting mysqlddaemon with databases from /var/lib/mysql
(3) 输入登陆用户命令
[root@centos7 mysql]# mysql -u root mysql
Reading table information for completion oftable and column names
You can turn off this feature to get aquicker startup with -A
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version:5.6.22-enterprise-commercial-advanced MySQL Enterprise Server - AdvancedEdition (Commercial)
Copyright (c) 2000, 2014, Oracle and/or itsaffiliates. All rights reserved.
Oracle is a registered trademark of OracleCorporation and/or its
affiliates. Other names may be trademarksof their respective
owners.
Type 'help;' or '\h' for help. Type '\c' toclear the current input statement.
(4)添加用户并赋予权限
mysql> use mysql;
mysql> create database MyShop; //建立一个数据库
//建立一个用户www并具备操做MyShop数据库的权限
mysql> grant all privileges on MyShop.* to 'www'@'localhost' identified by '888888';
mysql> flush privileges;
若是出现: The MySQL server is running with the –skip-grant-tables option so it cannot execute this statement
要先执行一下flush privileges,而后在执行 grant all 来建立用户
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
来查看一下权限
mysql> SELECT DISTINCT CONCAT('User: ''',user,'''@''',host,''';') AS query FROM user;
+------------------------------+
| query |
+------------------------------+
| User: 'root'@'127.0.0.1'; |
| User: 'root'@'::1'; |
| User: 'root'@'centos7'; |
| User: 'www'@'localhost'; |
| User: 'root'@'localhost'; |
+------------------------------+
6 rows in set (0.00 sec)
mysql> show grants for 'www'@'localhost';
+----------------------------------------------------------------------------------------------------------------+
| Grants for www@localhost |
+----------------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'www'@'localhost' IDENTIFIED BY PASSWORD '*8E02B7AE57F9A19E165EB45CD3F705BF66985B85' |
| GRANT ALL PRIVILEGES ON `MyShop`.* TO 'www'@'localhost' |
+----------------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)
(5) 输入修改root密码SQL语句
mysql> udpate user SET Password=PASSWORD('root') where USER='root';
Query OK, 4 rows affected (0.04 sec)
Rows matched: 4 Changed: 4 Warnings: 0
(6) 输入数据刷新命令
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
(7) 退出
mysql> quit
Bye
(8) 启动MYSQL
[root@centos7 mysql]# service mysql start
Starting MySQL SUCCESS!
登陆mysql,查看全部数据库:
[root@centos7 mysql]# mysql -u root -p
mysql> show databases;
ERROR 1820 (HY000):You must SET PASSWORD before executing this statement
提示要再设置一下密码:
mysql> SET PASSWORD = PASSWORD('passok');
Query OK, 0 rows affected (0.00 sec)
显示数据库:
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)
进入数据库建立表、显示表:
mysql> use test;
Database changed
mysql> show tables;
Empty set (0.02 sec)
mysql>create table testTable(name char(15) not null,passwd char(15) not null);
Query OK, 0 rows affected (0.87 sec)
mysql> show tables;
+----------------+
| Tables_in_test |
+----------------+
| testTable |
+----------------+
1 row in set (0.00 sec)
mysql安装后三个主要的目录及其功能:
/var/lib/mysql 数据库文件
/usr/share/mysql 命令及配置文件
/usr/bin mysqladmin、mysqldump等命令
设置mysql开机自启动
设置开机启动服务选择使用chkconfig命令,能够看到咱们永久性关闭iptables就用的这个命令,命令的格式以下:
chkconfig 功能说明:检查,设置系统的各类服务。
语法:chkconfig [--add][--del][--list][系统服务]或 chkconfig [--level <等级代号>][系统服务][on/off/reset]
--add 添加服务
--del 删除服务
--list 查看各服务启动状态
我这里安装好了mysql以后默认就是开机自启动的:
[root@centos7 mysql]# chkconfig --list mysql
注意:该输出结果只显示 SysV 服务,并不包含原生 systemd 服务。SysV 配置数据可能被原生 systemd 配置覆盖。
若是您想列出 systemd 服务,请执行 'systemctl list-unit-files'。
欲查看对特定 target 启用的服务请执行
'systemctl list-dependencies [target]'。
mysql 0:关 1:关 2:开 3:开 4:开 5:开 6:关
若是不是开机自启动,使用开启MySQL服务自动开启命令:
chkconfig mysqld on
chkconfig mysql on
搜集的安装过程当中遇到的问题:
1: 启动时
[root@centos7 mysql]#service mysql start
获得错误:ERROR!The server quit without updating PID file
这里主要是由于:selinux惹的祸,若是是centos系统,默认会开启selinux。
解决方法是关闭它,打开/etc/selinux/config,把SELINUX=enforcing改成SELINUX=disabled后存盘退出重启机器。
而后再启动mysql就没问题了:
2:
FATAL ERROR: please install the following Perl modules before executing /usr/local/mysql/scripts/mysql_install_db:
初始化mysql数据库提示缺乏Data:dumper模块解决方法
Data::Dumper
解决方法 :安装autoconf库
命令:yum-y install autoconf
安装完autoconf库,再运行
/usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql/
3: 启动时:Starting MySQL... ERROR! The server quit without updating PID file (/var/lib/mysql/localhost.localdomain.pid)
没有权限:
chown -R mysql.mysql /var/lib/mysql ##该命令仅为示例,其中/data/mysql就是mysql配置文件中datadir的目录 ##若为空,则默认为mysql安装目录下的data文件夹下
http://www.cnblogs.com/leohe/p/6729014.html
http://www.cnblogs.com/linkstar/p/6510713.html
http://blog.csdn.net/mlz_2/article/details/72312336
http://blog.csdn.net/z_102865/article/details/52162492
https://dev.mysql.com/doc/refman/5.7/en/mysql-cluster-install-windows-binary.html