Linux安装MySQL的两种方法

原文链接:http://blog.csdn.net/superchanon/article/details/8546254

---------------------------------------------------------------------------------------


1.       运行平台:CentOS 6.3 x86_64,基本等同于RHEL 6.3

2.       安装方法:

安装MySQL主要有两种方法:一种是通过源码自行编译安装,这种适合高级用户定制MySQL的特性,这里不做说明;另一种是通过编译过的二进制文件进行安装。二进制文件安装的方法又分为两种:一种是不针对特定平台的通用安装方法,使用的二进制文件是后缀为.tar.gz的压缩文件;第二种是使用RPM或其他包进行安装,这种安装进程会自动完成系统的相关配置,所以比较方便。

3.       下载安装包:

a.  官方下载地址:

http://dev.mysql.com/downloads/mysql/#downloads

或镜像文件下载:

http://dev.mysql.com/downloads/mirrors.html

2.  下载文件(根据操作系统选择相应的发布版本):

a.  通用安装方法

mysql-5.5.29-linux2.6-x86_64.tar.gz

b.       RPM安装方法:

MySQL-server-5.5.29-2.el6.x86_64.rpm

MySQL-client-5.5.29-2.el6.x86_64.rpm

4.       通用安装步骤

a.       检查是否已安装,grep的-i选项表示匹配时忽略大小写

[root@localhost JavaEE]#rpm -qa|grep -i mysql

mysql-libs-5.1.61-4.el6.x86_64

*可见已经安装了库文件,应该先卸载,不然会出现覆盖错误。注意卸:载时使用了--nodeps选项,忽略了依赖关系:

[root@localhost JavaEE]#rpm -e mysql-libs-5.1.61-4.el6.x86_64 --nodeps

b.     添加mysql组和mysql用户,用于设置mysql安装目录文件所有者和所属组。

[root@localhost JavaEE]#groupadd mysql

[root@localhost JavaEE]#useradd -r -g mysql mysql

*useradd -r参数表示mysql用户是系统用户,不可用于登录系统。

c.  将二进制文件解压到指定的安装目录,我们这里指定为/usr/local

[root@localhost ~]# cd/usr/local/

[root@localhost local]#tar zxvf /path/to/mysql-5.5.29-linux2.6-x86_64.tar.gz

*加压后在/usr/local/生成了解压后的文件夹mysql-5.5.29-linux2.6-x86_64,这名字太长,我们为它建立一个符号链接mysql,方便输入。

[root@localhost local]#ln -s mysql-5.5.29-linux2.6-x86_64 mysql

d.     /usr/local/mysql/下的目录结构

Directory

Contents of Directory

bin

Client programs and the mysqld server

data

Log files, databases

docs

Manual in Info format

man

Unix manual pages

include

Include (header) files

lib

Libraries

scripts

mysql_install_db

share

Miscellaneous support files, including error messages, sample configuration files, SQL for database installation

sql-bench

Benchmarks

e.     进入mysql文件夹,也就是mysql所在的目录,并更改所属的组和用户。

[root@localhost local]#cd mysql

[root@localhost mysql]#chown -R mysql .

[root@localhost mysql]#chgrp -R mysql .

f.       执行mysql_install_db脚本,对mysql中的data目录进行初始化并创建一些系统表格。注意mysql服务进程mysqld运行时会访问data目录,所以必须由启动mysqld进程的用户(就是我们之前设置的mysql用户)执行这个脚本,或者用root执行,但是加上参数--user=mysql。

[root@localhost mysql]scripts/mysql_install_db --user=mysql

*如果mysql的安装目录(解压目录)不是/usr/local/mysql,那么还必须指定目录参数,如

[root@localhost mysql]scripts/mysql_install_db --user=mysql \

         --basedir=/opt/mysql/mysql \

         --datadir=/opt/mysql/mysql/data

*将mysql/目录下除了data/目录的所有文件,改回root用户所有,mysql用户只需作为mysql/data/目录下所有文件的所有者。

[root@localhost mysql]chown -R root .

[root@localhost mysql]chown -R mysql data

g.     复制配置文件

[root@localhost mysql] cp support-files/my-medium.cnf /etc/my.cnf

h.  将mysqld服务加入开机自启动项。

*首先需要将scripts/mysql.server服务脚本复制到/etc/init.d/,并重命名为mysqld。

[root@localhostmysql]  cp support-files/mysql.server /etc/init.d/mysqld

*通过chkconfig命令将mysqld服务加入到自启动服务项中。

[root@localhost mysql]#chkconfig --add mysqld

*注意服务名称mysqld就是我们将mysql.server复制到/etc/init.d/时重命名的名称。

*查看是否添加成功

[root@localhost mysql]#chkconfig --list mysqld

mysqld   0:off 1:off        2:on        3:on        4:on        5:on        6:off

i.  重启系统,mysqld就会自动启动了。

*检查是否启动

[root@localhost mysql]#netstat -anp|grep mysqld

tcp        0     0 0.0.0.0:3306               0.0.0.0:*                   LISTEN      2365/mysqld        

unix  2     [ ACC ]     STREAM     LISTENING     14396 2365/mysqld        /tmp/mysql.sock

*如果不想重新启动,那可以直接手动启动。

[root@localhost mysql]#service mysqld start

Starting MySQL.. SUCCESS!

j.       运行客户端程序mysql,在mysql/bin目录中,测试能否连接到mysqld。

[root@localhost mysql]#/usr/local/mysql/bin/mysql

Welcome to the MySQLmonitor.  Commands end with ; or \g.

Your MySQL connection idis 2

Server version:5.5.29-log MySQL Community Server (GPL)

 

Copyright (c) 2000, 2012,Oracle and/or its affiliates. All rights reserved.

Oracle is a registeredtrademark of Oracle Corporation and/or its affiliates. Other names may betrademarks of their respective owners.

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

mysql> quit

Bye

*此时会出现mysql>命令提示符,可以输入sql语句,输入quit或exit退出。为了避免每次都输入mysql的全路径/usr/local/mysql/bin/mysql,可将其加入环境变量中,在/etc/profile最后加入两行命令:

MYSQL_HOME=/usr/local/mysql

export PATH=$PATH:$MYSQL_HOME/bin

这样就可以在shell中直接输入mysql命令来启动客户端程序了

[root@localhost mysql]#mysql

Welcome to the MySQLmonitor.  Commands end with ; or \g.

Your MySQL connection idis 3

Server version:5.5.29-log MySQL Community Server (GPL)

Copyright (c) 2000, 2012,Oracle and/or its affiliates. All rights reserved.

Oracle is a registeredtrademark of Oracle Corporation and/or its

affiliates. Other namesmay be trademarks of their respective

owners.

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

mysql>

 

第二种方法 

 RPM安装步骤

a.       检查是否已安装,grep的-i选项表示匹配时忽略大小写

[root@localhost JavaEE]#rpm -qa|grep -i mysql

mysql-libs-5.1.61-4.el6.x86_64

可见已经安装了库文件,应该先卸载,不然会出现覆盖错误。注意卸载时使用了--nodeps选项,忽略了依赖关系:

[root@localhost JavaEE]#rpm -e mysql-libs-5.1.61-4.el6.x86_64 --nodeps

2.     安装MySQL的服务器端软件,注意切换到root用户:

[root@localhost JavaEE]#rpm -ivh MySQL-server-5.5.29-2.el6.x86_64.rpm

安装完成后,安装进程会在Linux中添加一个mysql组,以及属于mysql组的用户mysql。可通过id命令查看:

[root@localhost JavaEE]#id mysql

uid=496(mysql)gid=493(mysql) groups=493(mysql)

MySQL服务器安装之后虽然配置了相关文件,但并没有自动启动mysqld服务,需自行启动:

[root@localhost JavaEE]#service mysql start

Starting MySQL.. SUCCESS!

可通过检查端口是否开启来查看MySQL是否正常启动:

[root@localhost JavaEE]#netstat -anp|grep 3306

tcp        0     0 0.0.0.0:3306               0.0.0.0:*                   LISTEN      34693/mysqld

c.  安装MySQL的客户端软件:

[root@localhost JavaEE]#rpm -ivh MySQL-client-5.5.29-2.el6.x86_64.rpm

如果安装成功应该可以运行mysql命令,注意必须是mysqld服务以及开启:

[root@localhost JavaEE]#mysql

Welcome to the MySQLmonitor.  Commands end with ; or \g.

Your MySQL connection idis 1

Server version: 5.5.29MySQL Community Server (GPL)

Copyright (c) 2000, 2012,Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademarkof Oracle Corporation and/or its affiliates. Other names may be trademarks oftheir respective owners.

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

mysql>

d.  RPM安装方式文件分布

Directory

Contents of Directory

/usr/bin

Client programs and scripts

/usr/sbin

The mysqld server

/var/lib/mysql

Log files, databases

/usr/share/info

Manual in Info format

/usr/share/man

Unix manual pages

/usr/include/mysql

Include (header) files

/usr/lib/mysql

Libraries

/usr/share/mysql

Miscellaneous support files, including error messages, character set files, sample configuration files, SQL for database installation

/usr/share/sql-bench

Benchmarks

 

 

---------2016-08-26--松门一枝花补充--------

但我安装时报错:

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

-----安装好serve的时候,有下面的提示:-----

适合5.7之前的版本。之后的请移步此处

A RANDOM PASSWORD HAS BEEN SET FOR THE MySQL root USER !
You will find that password in '/root/.mysql_secret'.


You must change that password on your first connect,
no other statement but 'SET PASSWORD' will be accepted.
See the manual for the semantics of the 'password expired' flag.


Also, the account for the anonymous user has been removed.


In addition, you can run:


  /usr/bin/mysql_secure_installation


which will also give you the option of removing the test database.
This is strongly recommended for production servers.


See the manual for more instructions.


Please report any problems at http://bugs.mysql.com/


The latest information about MySQL is available on the web at


  http://www.mysql.com


Support MySQL by buying support/licenses at http://shop.mysql.com


New default config file was created as /usr/my.cnf and
will be used by default by the server when you start it.
You may edit this file to change server settings


进入:mysql_secret 

适合5.7之前的版本。之后的请移步此处

[root@hello110 ~]# cat .mysql_secret 
# The random password set for the root user at Sat Aug 27 01:33:41 2016 (local time): RsD3_afVuO4zOSxi


用里面的密码登录:


[root@hello110 hello]# mysql -uroot -pRsD3_afVuO4zOSxi     

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 15
Server version: 5.6.32


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> set password = password('123456');
Query OK, 0 rows affected (0.16 sec)


修改密码后,就可以使用了。大笑


mysql> 



本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/539295.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

jenkins 手动执行_想知道如何用Jenkins自动执行Python脚本输出测试报告?

前言在用python做自动化测试时,我们写好代码,然后需要执行才能得到测试报告,这时我们可以通过 Jenkins 来进一步完成自动化工作。借助Jenkins,我们可以结合 Git/SVN 自动拉取代码,可以设置定时构建,接着就可…

VR 影院,约吗?

世界第一家 VR 影院已经开张,朋友,去不? 世界第一家 VR 影院正式开张 (无大屏的 VR 电影院) 在被称为 VR 元年的 2016 年,越来越多的人加入了这个新兴的领域,各种传统应用也在被 VR 包装之后以…

redis cluster 分布式锁_关于分布式锁原理的一些学习与思考redis分布式锁,zookeeper分布式锁...

首先分布式锁和我们平常讲到的锁原理基本一样,目的就是确保,在多个线程并发时,只有一个线程在同一刻操作这个业务或者说方法、变量。在一个进程中,也就是一个jvm 或者说应用中,我们很容易去处理控制,在jdk …

会计行业被计算机取代马云,会计人:为什么我神烦“人工智能取代说”?

原标题:会计人:为什么我神烦“人工智能取代说”?原创来源:学会计有方法从财会机器人诞生到马云的无人商店,全行业掀起了一股“人工智能取代说”的热潮。有些财会朋友在一轮又一轮的信息轰炸下,倍感压力&…

mysql5.6允许远程服务器访问数据库

创建一个mysql用户,并设置可以远程访问 grant usage on *.* to fredlocalhost identified by fred;//创建用户fred密码ferdselect host,user,password from mysql.user where userfred;//查看记录 grant all privileges on *.* to fred%identified by fred;//设置可以远程访问…

sp烘焙流程_小手雷-PBR材质流程(一)——(基本材质)

小手雷-PBR材质流程(一)Substance Painter生存手册经过了12个章节的讲解后,已经完结了(。・ω・。)相信大家经过了生存手册这一基础教程过后,对Substance Painter这款软件已经有了比较坚实的基础了,…

MyBatis-进阶2

typeHandler typeHandler有什么用? 你可以重写类型处理器或创建你自己的类型处理器来处理不支持的或非标准的类型。 具体做法为:实现 org.apache.ibatis.type.TypeHandler 接口, 或继承一个很便利的类 org.apache.ibatis.type.BaseTypeHandle…

python中 r是什么意思_python中rb含义理解

Python文件读写的几种模式: r,rb,w,wb 那么在读写文件时,有无b标识的的主要区别在哪里呢? 文件使用方式标识 r:默认值,表示从文件读取数据 w:表示要向文件写入数据,并截断以前的内容 a:表示要向文件写入数据&#xff0…

哈佛大学计算机生物科学,生命科学专业

【出国留学网】昨日,泰晤士报公布了最新版2018年世界大学生命科学排名,哈佛大学位列第一。本文是关于世界各国大学在本次生命科学排名中的具体表现,供你选校参考。The 2018 Times Higher Education World University Rankings’ table for li…

怎样呵护友谊_呵护真正的友情,助力漫长的人生

友情,即友谊,是指朋友和朋友之间的感情。它是一种很美妙的东西,可以让你在失落的时候变得高兴起来,可以让你走出苦海,去迎接新的人生。它就像一种你无法说出又可以感到快乐无比的东西。只有拥有真正朋友的人&#xff0…

【Day41】Python之路——AJAX

什么是AJAX AJAX Asynchronous JavaScript and XML(异步的 JavaScript 和 XML)。 优点: 不重新加载整个页面的情况下,可以与服务器交换数据并更新部分网页内容 不需要任何浏览器插件,但需要用户允许JavaScript在浏览器上执行 同源…

LINUX重启MYSQL的命令

原文:http://blog.csdn.net/liuyong0818/article/details/5693336 ------------------------原文有错误,本文转载时已修改--------- 如何启动/停止/重启MySQL 一、启动方式 1、使用 service 启动:service mysql start 2、使用 mysql 脚…

html css子标签,HTML+CSS系列:CSS选择器(标签、ID、类、通配符、后代、子元素、并集、伪类)...

一.标签选择器Documenth1 {color: red;}h2{color: green;}Hello World!Hello World!Hello !Hello !二.类选择器Document.box {color: green;}.box1 {font-size: 26px;}Hello World!Hello World!三.ID选择器Document#box{color: green;}Hello World!四.通配符选择器Document*{ma…

aes离线解密工具_如何在Python中解密OpenSSL AES加密文件?

OpenSSL为AES加密提供了一种流行的(但不安全 - 见下文!)命令行界面:openssl aes-256-cbc -salt -in filename -out filename.encPython以PyCrypto包的形式支持AES,但它只提供工具。如何使用Python / PyCrypto解密使用OpenSSL加密的文件&#…

什么是Hive

Hive 是建立在 Hadoop 上的数据仓库基础构架。 它提供了一系列的工具,可以用来进行数据提取转化加载(ETL ),这是一种可以存储、查询和分析存储在 Hadoop 中的大规模数据的机制。 Hive 定义了简单的类 SQL 查询语言&#xff0c…

VUE-搜索过滤器

VUE非常实用的搜索过滤&#xff0c;喜欢点个赞哦 废话不多说&#xff0c;先来看看效果 1 引入vue <script src"https://cdn.jsdelivr.net/npm/vue"></script>2 HTML <div id"app"><input v-modelsearch /><ul v-if"search…

单选按钮必填会有红色选中提示吗_为什么单选按钮和复选框不能共存?

以下内容由摹客团队翻译整理&#xff0c;仅供学习交流&#xff0c;摹客设计协作一站式云平台&#xff0c;从产品、设计到开发&#xff0c;摹客来解决。单选按钮和复选框长期以来一直都是容易导致用户困惑的组件。这两个组件通常用于相同的情景下&#xff0c;但看起来又完全不同…

用计算机进行服装设计,电脑服装设计(10制版1班)

《电脑服装设计》课程教学大纲课程名称:电脑服装设计(Corldraw和Photoshop)课程代码:10617313总学时&#xff1a;68课时适用专业&#xff1a;10制版方向学生开课单位&#xff1a;时装设计学院一、讲课内容第一章 CORELDROW软件整体的介绍第一节绪论, 与其他图形绘制软件的区别及…

程序包org.junit.jupiter.api不存在

在跑项目的时候遇到这个问题&#xff0c;去看pom文件一切正常&#xff0c;也引入了这个依赖 <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.13.2</version> <scope>test</scope&…

thrift介绍及应用(一)—介绍

原文&#xff1a;http://blog.csdn.net/guxch/article/details/12157151 ------------------------------------------------------------------------------------ 一、概述 Thrift是Apache下的一个子项目&#xff0c;最早是Facebook的项目&#xff0c;后来Facebook提供给Apa…