前提:

环境:workstation 11 + CentOS 7 + mysql-5.6.40

安装前先查看服务器里是否有老版本的mysql已经被安装了

rpm -qa|grep mysql

如果有就删除掉旧版本的mysql即可

rpm -e (上面那条命令得到的信息,即mysql软件包名) --nodeps

正式安装:

1.上传安装包到/usr/local/目录下,解压缩,重命名,配置环境变量

[root@hadoop ~]# cd /usr/local/
[root@hadoop local]# tar xzvf mysql-5.6.40-linux-glibc2.12-x86_64.tar.gz
[root@hadoop local]# mv mysql-5.6.40-linux-glibc2.12-x86_64 mysql
[root@hadoop ~]# vi /etc/profile
添加变量:export MYSQL_HOME=/usr/local/mysql
在PATH后面添加 :$MYSQL_HOME/bin
[root@hadoop ~]# source /etc/profile

2.创建目录,添加用户组和用户

[root@hadoop local]# mkdir -p /data/mysql_data
[root@hadoop local]# mkdir -p /data/mysql_log
[root@hadoop local]# mkdir -p /data/log-bin
[root@hadoop local]# groupadd mysql
[root@hadoop local]# useradd -g mysql mysql
[root@hadoop local]# chown -R mysql.mysql /data/mysql_data /data/mysql_log/ /data/log-bin/
[root@hadoop local]# chown -R mysql.mysql /usr/local/mysql

3.配置my.cnf文件。根据自己需求填写,以下只是一个大概的例子

[root@hadoop local]# vi /etc/my.cnf
[mysqld]
# GENERAL #
user = mysql
#default-storage-engine = INNODB
default-storage-engine = MyISAM socket=/data/mysql_data/mysql.sock
pid-file=/data/mysql_data/mysql.pid
port = # MyISAM #
key_buffer_size = 1000M
myisam-recover-options = FORCE,BACKUP # SAFETY #
max_allowed_packet = 16M
max_connect_errors =
skip_name_resolve # DATA STORAGE #
datadir = /data/mysql_data/
long_query_time = # BINARY LOGGING #
binlog_format=ROW
log-bin = /data/log-bin/mysql-bin-
expire_logs_days =
sync_binlog =
server-id =
max_binlog_size = 500M # REPLICATION #
relay-log = /data/log-bin/relay-bin-
slave-net-timeout = # CACHES AND LIMITS #
tmp_table_size = 32M
max_heap_table_size =32M
max_connections =
thread_cache_size =
open_files_limit=
table_definition_cache =
table_open_cache = # INNODB #
innodb_data_file_path = ibdatal:128M;ibdata2:10M:autoextend
innodb_flush_method = O_DIRECT
innodb_log_files_in_group =
innodb_lock_wait_timeout =
innodb_log_file_size = 256M
innodb_flush_log_at_trx_commit =
innodb_file_per_table =
innodb_thread_concurrency =
innodb_buffer_pool_size = 8G # LOGGING #
log-error = /data/mysql_log/mysql-error-.log
log-queries-not-using-indexes =
slow-query-log =
long_query_time =
slow_query_log_file = /data/mysql_log/mysql-slow-.log # FOR SLAVE #
#log-slave-updates = true
#gtib-mode = on
#enforce-gtib-consistency = true
#master-info-repository = TABLE
#relay-log-info-repository = TABLE
#sync-master-info =
#slave-parallel-workers =
#binlog-checksum = CRC32
#master-verify-checksum =
#slave-sql-verify-checksum =
#binlog-rows-query-log-events =
#report-port =
#report-host = 192.168.42.133

my.cnf

4.配置系统服务

[root@hadoop local]# cp -af /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@hadoop local]# vi /etc/init.d/mysqld
#修改两个变量,分别在46行和47行,set nu显示编辑文件行数
basedir=/usr/local/mysql
datadir=/data/mysql_data
[root@hadoop local]# chmod 755 /etc/init.d/mysqld
[root@hadoop local]# chkconfig --add mysqld
[root@hadoop local]# chkconfig --level 345 mysqld on

5.初始化数据库

[root@hadoop mysql]# ./scripts/mysql_install_db --user=mysql --defaults-file=/etc/my.cnf

6.启动数据库

[root@hadoop ~]# service mysqld start

7.执行mysql命令报错并解决

[root@hadoop ~]# mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

解决方法:执行软链接

[root@hadoop ~]# ln -s /data/mysql_data/mysql.sock /tmp/mysql.sock
[root@hadoop ~]# mysql     #再次查看,成功登录mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is
Server version: 5.6.-log 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> exit
Bye
[root@hadoop ~]#

再次执行mysql查看,成功登录mysql

8.修改root用户密码,增加mysql的安全性

mysqladmin -u root password 'root' #设置密码后再执行mysql就无法登录mysql了
mysql -uroot -proot #登录mysql需要输入密码
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION; #允许root用户远程访问
mysql> FLUSH PRIVILEGES; #刷新权限
mysql> exit
[root@hadoop ~]# mysqladmin -u root password 'root' #设置密码
Warning: Using a password on the command line interface can be insecure.
[root@hadoop ~]# mysql #无法登录
ERROR (): Access denied for user 'root'@'localhost' (using password: NO)
[root@hadoop ~]# mysql -uroot -p #这样登录
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is
Server version: 5.6.-log 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> exit
Bye
[root@hadoop ~]# mysql -uroot -proot #或者这样登录
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is
Server version: 5.6.-log 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> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION; #远程访问
Query OK, rows affected (0.03 sec) mysql> FLUSH PRIVILEGES; #刷新权限
Query OK, rows affected (0.00 sec)

9.删除匿名账户。因为mysql数据库安装完之后自带一个匿名账户,这非常容易增加数据库受到安全攻击的风险。

mysql> update mysql.user set password=PASSWORD('your password') where user='';
mysql> FLUSH PRIVILEGES;
mysql> update mysql.user set password=PASSWORD('your password') where user='';
Query OK, rows affected (0.05 sec)
Rows matched: Changed: Warnings: mysql> FLUSH PRIVILEGES;
Query OK, rows affected (0.00 sec)

至此,我们的mysql就算安装完成了。

10.测试mysql是否可以远程登录。
由于HIVE有可能是调用远程的mysql进行元数据处理,我们需要测试一下是否可以远程登录mysql,为以后做准备。

如果你Windows本地装过mysql的话,直接cmd进入命令行,输入mysql -h 192.168.42.133 -uroot -proot,查看是否能登录。(我可以登录)

C:\Users\Administrator>mysql -h 192.168.42.133 -uroot -proot
mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is
Server version: 5.6.-log 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>

如果你Windows本地没有安装过mysql的话,可以安装workbench,这个软件可以远程登录mysql进行管理和开发。

点击 Test Connection,显示连接成功,如下图

然后点击ok-->ok,可建立远程连接。

mysql在linux上的安装的更多相关文章

  1. Mysql基于Linux上的安装

    MySQL 在Linux/Unix安装 所有平台的 MySQL 下载地址为: MySQL 下载 . 挑选需要的 MySQL Community Server 版本及对应的平台. 注意:安装过程需要通过 ...

  2. 大数据平台搭建 - Mysql在linux上的安装

    一.简介 MySQL是一个关系型数据库系统,由瑞典MySQL AB 公司开发,目前属于 Oracle 旗下产品.MySQL 是最流行的关系型数据库管理系统之一,在 WEB 应用方面,MySQL是最好的 ...

  3. Linux上编译安装PHP

    这篇文章主要介绍了关于Linux上编译安装PHP,有着一定的参考价值,现在分享给大家,有需要的朋友可以参考一下 之前在服务器上编译安装了PHP运行环境,但是安装完过了一段时间就差不多忘记了,只是零零星 ...

  4. Linux上centOs6+安装mysql5.7详细教程 - 前端小鱼塘

    https://coyhom.github.io/ 人类的本质是复读机,作为一个非linux专业人员学习linux最好的办法是重复 环境centos6.5 版本5.7 1: 检测系统是否自带安装mys ...

  5. jemalloc在linux上从安装到使用

    jemalloc在linux上从安装到使用 上次在引导大家安装Redis时提到可能会报错:  发现了redis有用到jemalloc. 首先,jemalloc是干什么的? 我们看看作者自己的介绍: j ...

  6. 分布式缓存技术redis学习系列(一)——redis简介以及linux上的安装

    redis简介 redis是NoSQL(No Only SQL,非关系型数据库)的一种,NoSQL是以Key-Value的形式存储数据.当前主流的分布式缓存技术有redis,memcached,ssd ...

  7. GIT在Linux上的安装和使用简介

    GIT最初是由Linus Benedict Torvalds为了更有效地管理Linux内核开发而创立的分布式版本控制软件,与常用的版本控制工具如CVS.Subversion不同,它不必服务器端软件支持 ...

  8. 分布式缓存技术redis学习(一)——redis简介以及linux上的安装

    redis简介 redis是NoSQL(No Only SQL,非关系型数据库)的一种,NoSQL是以Key-Value的形式存储数据.当前主流的分布式缓存技术有redis,memcached,ssd ...

  9. 在Linux上怎么安装和配置Apache Samza

    samza是一个分布式的流式数据处理框架(streaming processing),它是基于Kafka消息队列来实现类实时的流式数据处理的.(准确的说,samza是通过模块化的形式来使用kafka的 ...

随机推荐

  1. python multiprocess pool模块报错pickling error

    问题 之前在调用class内的函数用multiprocessing模块的pool函数进行多线程处理的时候报了以下下错误信息: PicklingError: Can't pickle <type ...

  2. [DLX精确覆盖] hdu 1603 A Puzzling Problem

    题意: 给你n块碎片,这些碎片不能旋转.翻折. 问你能不能用当中的某些块拼出4*4的正方形. 思路: 精确覆盖裸题了 建图就是看看每一个碎片在4*4中能放哪些位置,这个就作为行. 列就是4*4=16个 ...

  3. [C] 在 C 语言编程中实现动态数组对象

    对于习惯使用高级语言编程的人来说,使用 C 语言编程最头痛的问题之一就是在使用数组需要事先确定数组长度. C 语言本身不提供动态数组这种数据结构,本文将演示如何在 C 语言编程中实现一种对象来作为动态 ...

  4. TensorFlow MNIST 问题解决

    TensorFlow MNIST 问题解决 一.数据集下载错误 错误:IOError: [Errno socket error] [Errno 101] Network is unreachable ...

  5. day_6.14py网络编程

    被动套接字和新建出套接字的区别 单任务,单线程,非阻塞!!!!服务器! #2018-6-14 16:51:25 #!--*--coding:utf-8 --*-- ''' 单进程,单任务 少的可以,多 ...

  6. es7 class装饰器

    文档http://es6.ruanyifeng.com/#docs/decorator ts文档 https://www.tslang.cn/docs/handbook/decorators.html ...

  7. Android开发实战(申明:来源于网络)

    Android开发实战(申明:来源于网络) 地址:http://so.csdn.net/so/search/s.do?q=Android%E5%BC%80%E5%8F%91%E5%AE%9E%E6%8 ...

  8. ARM v8中断机制和中断处理(转)

    https://blog.csdn.net/firefox_1980/article/details/40113637 https://blog.csdn.net/firefox_1980/artic ...

  9. JNUOJ 1032 - 食物处理器

    题目链接:http://jnuacm.club:8080/oj/problem_show.php?pid=1032   小明喜欢把土豆块放在食物处理器中处理.长度不超过H的土豆块放入处理器中,处理器每 ...

  10. day12:装饰器的进阶

    1,三元运算符:变量 = 条件返回True的结果 if 条件 else 条件返回false的结果:必须要有结果:必须要有if和else,只能是简单的情况. 2,传参包起来,星号打散 def outer ...