1、检查是否有安装
[root@JDDB mysql]# yum list installed | grep mysql
mysql-community-client.x86_64 5.6.39-2.el7 @mysql56-community
mysql-community-common.x86_64 5.6.39-2.el7 @mysql56-community
mysql-community-libs.x86_64 5.6.39-2.el7 @mysql56-community
mysql-community-release.noarch el7-5 installed
mysql-community-server.x86_64 5.6.39-2.el7 @mysql56-community
2、卸载删除
[root@JDDB mysql]# yum -y remove mysql-community-*
同类文章:
http://blog.csdn.net/zengmingen/article/details/52326253
以root账号登录完成以下操作
1、修改yum为阿里云的(可选),修改后下载快。
方法见博文:http://blog.csdn.net/zengmingen/article/details/52956276
2、使用yum安装mysql server。
yum install -y mysql-server
如果提示未找到 mysql-server,使用下面的步骤:
下载 MySQL Yum Repository
https://repo.mysql.com/
地址为 http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
执行
wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
如果提示
-bash: wget: 未找到命令
,请先执行yum install wget
安装 wget
安装
添加 MySQL Yum Repository
添加 MySQL Yum Repository 到你的系统 repository 列表中,执行
yum localinstall mysql-community-release-el7-5.noarch.rpm
显示
[root@bogon software]# yum localinstall mysql-community-release-el7-5.noarch.rpm
已加载插件:fastestmirror
正在检查 mysql-community-release-el7-5.noarch.rpm: mysql-community-release-el7-5.noarch
mysql-community-release-el7-5.noarch.rpm 将被安装
正在解决依赖关系
--> 正在检查事务 ---> 软件包 mysql-community-release.noarch.0.el7-5 将被 安装 --> 解决依赖关系完成 依赖关系解决 ================================================================================ Package 架构 版本 源 大小 ================================================================================ 正在安装: mysql-community-release noarch el7-5 /mysql-community-release-el7-5.noarch 4.3 k 事务概要 ================================================================================ 安装 1 软件包 总计:4.3 k 安装大小:4.3 k Is this ok [y/d/N]
提示是否 OK ,输入 y
Is this ok [y/d/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction正在安装 : mysql-community-release-el7-5.noarch 1/1验证中 : mysql-community-release-el7-5.noarch 1/1已安装:mysql-community-release.noarch 0:el7-5完毕!
提示“完成!”,则说明 源添加成功。
验证下是否添加成功
yum repolist enabled | grep "mysql.*-community.*"
可以看到下面内:
[root@bogon software]# yum repolist enabled | grep "mysql.*-community.*"
mysql-connectors-community/x86_64 MySQL Connectors Community 1
mysql-tools-community/x86_64 MySQL Tools Community 1
mysql56-community/x86_64 MySQL 5.6 Community Server 13
选择要启用 MySQL 版本
查看 MySQL 版本,执行
yum repolist all | grep mysql
可以看到 5.5, 5.7 版本是默认禁用的,因为现在最新的稳定版是 5.6
[root@bogon software]# yum repolist all | grep mysql
mysql-connectors-community/x86_64 MySQL Connectors Community 启用: 14
mysql-connectors-community-source MySQL Connectors Community - Sourc 禁用
mysql-tools-community/x86_64 MySQL Tools Community 启用: 17
mysql-tools-community-source MySQL Tools Community - Source 禁用
mysql55-community/x86_64 MySQL 5.5 Community Server 禁用
mysql55-community-source MySQL 5.5 Community Server - Sourc 禁用
mysql56-community/x86_64 MySQL 5.6 Community Server 启用: 139
mysql56-community-source MySQL 5.6 Community Server - Sourc 禁用
mysql57-community-dmr/x86_64 MySQL 5.7 Community Server Develop 禁用
mysql57-community-dmr-source MySQL 5.7 Community Server Develop 禁用
通过 Yum 来安装 MySQL
执行
yum install mysql-server
Yum 会自动处理 MySQL 与其他组件的依赖关系:
---------------------------------------
如果报错,内容含有
Error: Package: mysql-community-libs-5.6.35-2.el7.x86_64 (mysql56-community)Requires: libc.so.6(GLIBC_2.17)(64bit)
Error: Package: mysql-community-server-5.6.35-2.el7.x86_64 (mysql56-community)Requires: libc.so.6(GLIBC_2.17)(64bit)
Error: Package: mysql-community-server-5.6.35-2.el7.x86_64 (mysql56-community)Requires: systemd
Error: Package: mysql-community-server-5.6.35-2.el7.x86_64 (mysql56-community)Requires: libstdc++.so.6(GLIBCXX_3.4.15)(64bit)
Error: Package: mysql-community-client-5.6.35-2.el7.x86_64 (mysql56-community)Requires: libc.so.6(GLIBC_2.17)(64bit)You could try using --skip-broken to work around the problemYou could try running: rpm -Va --nofiles --nodigest
解决:
#yum install glibc.i686
# yum list libstdc++*
解决方法二
#cd /etc/yum.repos.d/
-
#sudo vi mysql-community.repo
-
找到mysql-56-community
-
将enable置为0 enable=0
-
重新安装mysql sudo yum install mysql-server
--------------------------------------------
service mysqld start //没错就是这么变态,没有i,mysql+d
chkconfig mysqld on //没错就是这么变态,没有i,mysql+d
3、给mysql root用户修改密码
设置MySQL 数据库root 用户的密码:
# mysqladmin -u root password '123456'
登录数据库:
# mysql -u root -p
输入密码
MySQL 授权远程访问 (先用root 登录mysql)
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '654321' WITH
GRANT OPTION;
mysql> FLUSH PRIVILEGES;
注意:本地登录和远程登录的密码是可以分开的,最好设置为不同
如果不要修改:
linux的root用户输入mysql。
-----mysql默认设置了root用户和密码。
-----Linux的root用户输入mysql的时候,会默认登陆root,无需输入用户名和密码
4、在mysql上创建用户
此处演示创建hive元数据库,并对hive用户进行授权
//创建数据库
create database if not exists hive_metadata;
//创建用户hive,密码hive,把赋予全部权限和允许任意机器远程访问(@'%' 'localhost''本机hosts名')
//hive_metadata 是hive数据库名
grant all privileges on hive_metadata.* to 'hive'@'%' identified by 'hive';
grant all privileges on hive_metadata.* to 'hive'@'localhost' identified by 'hive';
grant all privileges on hive_metadata.* to 'hive'@'本机hosts名' identified by 'hive';
//刷新权限
flush privileges;
--------以上就已经完成了mysql的安装和创建数据库和用户--------------
--------现在以Linux非root用户登陆mysql
演示以hadoop用户登陆
[hadoop@BD05 ~]$ mysql -uhive -phive
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.1.73 Source distribution
Copyright (c) 2000, 2013, 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 databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| hive_metadata |
| test |
+--------------------+
3 rows in set (0.00 sec)