热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

LinuxMySQL免安装及配置

http:jingyan.baidu.comarticlead310e80cf9ce81849f49ea2.html有些情况,为节省机器资源,多个人共用

http://jingyan.baidu.com/article/ad310e80cf9ce81849f49ea2.html


 有些情况,为节省机器资源,多个人共用一台Linux物理机器,但是数据库不许共用,这样就需要各自安装MySQL数据库软件了,但是RPM版需要root权限,那么可以选择免安装的MySQL;Windows也有免安装版的MySQL,不在此介绍。下面进行Linux环境免安装MySQL配置步骤介绍,本文以CentOS Linux为例,所安装MySQL版本为5.1.72,高手请飘过。



工具/原料

  • RedHat系列Linux发行版、mysql免安装包
  • 熟悉shell常用命令


方法/步骤

  1. 1

    下载MySQL软件包到指定目录

    /home/codebrother/mysql/mysql-5.1.72-linux-x86_64-glibc23.tar

  2. 2

    创建MySQL安装主目录

    我的机器以mysql_db命名为mysql的主目录,创建mysql_db目录,并进入mysql_db目录,如图一

    mkdir mysql_db

    cd mysql_db

    Linux MySQL免安装及配置
  3. 3

    解压缩MySQL软件包,如图二

    tar -xvf /home/codebrother/mysql/mysql-5.1.72-linux-x86_64-glibc23.tar

    Linux MySQL免安装及配置
  4. 4

    修改解压后的目录名称,如图三

    执行命令格式:mv 源目录名称 新目录名称

    mv mysql-5.1.72-linux-x86_64-glibc23 mysql-5.1.72

    Linux MySQL免安装及配置
  5. 5

    复制my-medium.cnf文件到指定目录,并命名为my.cnf,如图四、图五

    进入mysql-5.1.72目录,执行命令:

    cd mysql-5.1.72/support-files/

    cp my-medium.cnf ../my.cnf

    再返回mysql_db目录,看到my.cnf文件已经在此目录下

    Linux MySQL免安装及配置
    Linux MySQL免安装及配置
  6. 6

    配置my.cnf文件

    编辑my.cnf文件,默认内容如图六

    vim my.cnf

    Linux MySQL免安装及配置
  7. 7

    检查MySQL默认端口3306是否被占用,如图七

    执行命令:netstat -apn | grep 3306

    Linux MySQL免安装及配置
  8. 8

    3306已经被占用,那么换一个端口,建议端口号在10000以上,比如改成13306,如图八

    在[client]里修改port端口号

    port=13306

    在[client]里修改sock文件位置:

    socket = /home/codebrother/mysql_db/mysql-5.1.72/mysql.sock

    Linux MySQL免安装及配置
  9. 9

    在[mysqld]里修改port=13306

    port = 13306

    在[mysqld]里修改sock文件位置:

    socket = /home/codebrother/mysql_db/mysql-5.1.72/mysql.sock

    在[mysqld]里添加MySQL基础目录:

    basedir = /home/codebrother/mysql_db/mysql-5.1.72

    在[mysqld]里添加MySQL数据存储目录:

    datadir = /home/codebrother/mysql_db/mysql-5.1.72/data

    在[mysqld]里添加MySQL日志文件:

    log-error = /home/codebrother/mysql_db/mysql-5.1.72/logs/mysql_error.log

    在[mysqld]里添加MySQL进程文件:

    pid-file = /home/codebrother/mysql_db/mysql-5.1.72/mysql.pid

    在[mysqld]里添加指定MySQL数据库所属用户:

    user = codebrother  (这里填写你所用的linux用户)

    Linux MySQL免安装及配置
  10. 10

    按ESC键,输入:wq 即保存退出。

  11. 11

    创建logs目录

    在mysql_db目录下创建logs目录,如图十

    执行命令:mkdir logs

    Linux MySQL免安装及配置
  12. 12

    安装MySQL

    执行安装命令:

    ./script/mysql_install_db --defaults-file=my.cnf

  13. 13

    如果执行成功,会提示如下内容:

    [codebrother@codebrother mysql-5.1.72]$ ./scripts/mysql_install_db --defaults-file=my.cnf

    WARNING: The host 'codebrother' could not be looked up with resolveip.

    This probably means that your libc libraries are not 100 % compatible

    with this binary MySQL version. The MySQL daemon, mysqld, should work

    normally with the exception that host name resolving will not work.

    This means that you should use IP addresses instead of hostnames

    when specifying MySQL privileges !

    Installing MySQL system tables...

    150904 17:27:00 [Warning] '--skip-locking' is deprecated and will be removed in a future release. Please use '--skip-external-locking' instead.

    OK

    Filling help tables...

    150904 17:27:01 [Warning] '--skip-locking' is deprecated and will be removed in a future release. Please use '--skip-external-locking' instead.

    OK

    To start mysqld at boot time you have to copy

    support-files/mysql.server to the right place for your system

    PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !

    To do so, start the server, then issue the following commands:

    /home/codebrother/mysql_db/mysql-5.1.72/bin/mysqladmin -u root password 'new-password'

    /home/codebrother/mysql_db/mysql-5.1.72/bin/mysqladmin -u root -h codebrother password 'new-password'

    Alternatively you can run:

    /home/codebrother/mysql_db/mysql-5.1.72/bin/mysql_secure_installation

    which will also give you the option of removing the test

    databases and anonymous user created by default.  This is

    strongly recommended for production servers.

    See the manual for more instructions.

    You can start the MySQL daemon with:

    cd /home/codebrother/mysql_db/mysql-5.1.72 ; /home/codebrother/mysql_db/mysql-5.1.72/bin/mysqld_safe &

    You can test the MySQL daemon with mysql-test-run.pl

    cd /home/codebrother/mysql_db/mysql-5.1.72/mysql-test ; perl mysql-test-run.pl

    Please report any problems with the /home/codebrother/mysql_db/mysql-5.1.72/scripts/mysqlbug script!

  14. 14

    启动MySQL,如图十一

    执行命令:

    bin/mysqld_safe --defaults-file=my.cnf &

    Linux MySQL免安装及配置
  15. 15

    检查MySQL端口、sock文件、log日志文件

    检查端口,执行命令:

    netstat -an | apn 13306

    如图,代表mysql已经使用13306端口,正常运行,如图十二

    Linux MySQL免安装及配置
  16. 16

    查看sock文件是否存在,如图十三,即为正常状态

    Linux MySQL免安装及配置
  17. 17

    查看logs日志文件,内容如下,如果有错误,会提示Error,请仔细检查一下。

    [codebrother@codebrother mysql-5.1.72]$ cat logs/mysql_error.log

    150904 17:46:35 mysqld_safe Starting mysqld daemon with databases from /home/codebrother/mysql_db/mysql-5.1.72/data

    150904 17:46:35 [Warning] '--skip-locking' is deprecated and will be removed in a future release. Please use '--skip-external-locking' instead.

    150904 17:46:35 [Note] Plugin 'FEDERATED' is disabled.

    150904 17:46:35  InnoDB: Initializing buffer pool, size = 8.0M

    150904 17:46:35  InnoDB: Completed initialization of buffer pool

    InnoDB: The log sequence number in ibdata files does not match

    InnoDB: the log sequence number in the ib_logfiles!

    150904 17:46:35  InnoDB: Database was not shut down normally!

    InnoDB: Starting crash recovery.

    InnoDB: Reading tablespace information from the .ibd files...

    InnoDB: Restoring possible half-written data pages from the doublewrite

    InnoDB: buffer...

    150904 17:46:35  InnoDB: Started; log sequence number 0 44233

    150904 17:46:35 [Note] Recovering after a crash using mysql-bin

    150904 17:46:35 [Note] Starting crash recovery...

    150904 17:46:35 [Note] Crash recovery finished.

    150904 17:46:35 [Note] Event Scheduler: Loaded 0 events

    150904 17:46:35 [Note] /home/codebrother/mysql_db/mysql-5.1.72/bin/mysqld: ready for connections.

    Version: '5.1.72-log'  socket: '/home/codebrother/mysql_db/mysql-5.1.72/mysql.sock'  port: 13306  MySQL Community Server (GPL)

  18. 18

    访问MySQL数据库,如图十四

    执行命令格式:mysql -u用户名 -h127.0.0.1 -P端口号

    mysql -uroot -h127.0.0.1 -P13306

    Linux MySQL免安装及配置
  19. 19

    查看已有数据库,删除内置的test数据库,如图十五

    执行命令:

    showdatabases;

    drop database test;

    Linux MySQL免安装及配置
  20. 20

    查看内置MySQL用户,删除匿名用户,如图十六

    切换到mysql数据库,执行命令:

    use mysql;

    select host, user, password from user;

    Linux MySQL免安装及配置
  21. 21

    执行删除命令,并确认已经删除匿名用户,如图十七

    delete from user where user = '';

    Linux MySQL免安装及配置
  22. 22

    修改用户密码,如图十八

    use mysql;

    update user set password = password('root');

    Linux MySQL免安装及配置
  23. 23

    至此免安装MySQL配置已经完毕!

    END


注意事项

  • 免安装版MySQL不会自启动,包括service mysql start|stop|restart 是不识别的,需要另配置。
  • Linux配置自启动操作会在后续文章中编写
  • 如有不足之处,欢迎大家随时批评指正,共同学习,共同进步!




推荐阅读
  • 安装oracle软件1创建用户组、用户和目录bjdb节点下:[rootnode1]#groupadd-g200oinstall[rootnode1]#groupad ... [详细]
  • Linux如何安装Mongodb的详细步骤和注意事项
    本文介绍了Linux如何安装Mongodb的详细步骤和注意事项,同时介绍了Mongodb的特点和优势。Mongodb是一个开源的数据库,适用于各种规模的企业和各类应用程序。它具有灵活的数据模式和高性能的数据读写操作,能够提高企业的敏捷性和可扩展性。文章还提供了Mongodb的下载安装包地址。 ... [详细]
  • 本文详细介绍了在Linux虚拟化部署中进行VLAN配置的方法。首先要确认Linux系统内核是否已经支持VLAN功能,然后配置物理网卡、子网卡和虚拟VLAN网卡的关系。接着介绍了在Linux配置VLAN Trunk的步骤,包括将物理网卡添加到VLAN、检查添加的VLAN虚拟网卡信息以及重启网络服务等。最后,通过验证连通性来确认配置是否成功。 ... [详细]
  • 基于PgpoolII的PostgreSQL集群安装与配置教程
    本文介绍了基于PgpoolII的PostgreSQL集群的安装与配置教程。Pgpool-II是一个位于PostgreSQL服务器和PostgreSQL数据库客户端之间的中间件,提供了连接池、复制、负载均衡、缓存、看门狗、限制链接等功能,可以用于搭建高可用的PostgreSQL集群。文章详细介绍了通过yum安装Pgpool-II的步骤,并提供了相关的官方参考地址。 ... [详细]
  • 本文介绍了Python高级网络编程及TCP/IP协议簇的OSI七层模型。首先简单介绍了七层模型的各层及其封装解封装过程。然后讨论了程序开发中涉及到的网络通信内容,主要包括TCP协议、UDP协议和IPV4协议。最后还介绍了socket编程、聊天socket实现、远程执行命令、上传文件、socketserver及其源码分析等相关内容。 ... [详细]
  • 本文讨论了在Windows 8上安装gvim中插件时出现的错误加载问题。作者将EasyMotion插件放在了正确的位置,但加载时却出现了错误。作者提供了下载链接和之前放置插件的位置,并列出了出现的错误信息。 ... [详细]
  • Metasploit攻击渗透实践
    本文介绍了Metasploit攻击渗透实践的内容和要求,包括主动攻击、针对浏览器和客户端的攻击,以及成功应用辅助模块的实践过程。其中涉及使用Hydra在不知道密码的情况下攻击metsploit2靶机获取密码,以及攻击浏览器中的tomcat服务的具体步骤。同时还讲解了爆破密码的方法和设置攻击目标主机的相关参数。 ... [详细]
  • 本文介绍了在Windows环境下如何配置php+apache环境,包括下载php7和apache2.4、安装vc2015运行时环境、启动php7和apache2.4等步骤。希望对需要搭建php7环境的读者有一定的参考价值。摘要长度为169字。 ... [详细]
  • 微软评估和规划(MAP)的工具包介绍及应用实验手册
    本文介绍了微软评估和规划(MAP)的工具包,该工具包是一个无代理工具,旨在简化和精简通过网络范围内的自动发现和评估IT基础设施在多个方案规划进程。工具包支持库存和使用用于SQL Server和Windows Server迁移评估,以及评估服务器的信息最广泛使用微软的技术。此外,工具包还提供了服务器虚拟化方案,以帮助识别未被充分利用的资源和硬件需要成功巩固服务器使用微软的Hyper - V技术规格。 ... [详细]
  • Redis API
    安装启动最简启动命令行输入验证动态参数启动配置文件启动常用配置通用命令keysbdsize计算key的总数exists判断是否存在delkeyvalue删除指定的keyvalue成 ... [详细]
  • 本文介绍了使用readlink命令获取文件的完整路径的简单方法,并提供了一个示例命令来打印文件的完整路径。共有28种解决方案可供选择。 ... [详细]
  • LINUX学习之centos7营救模式
    今天卸载软件的时候,不小心把GNOME的一些组件给卸了,导致桌面无法正常开启,会卡在启动过程中,而我的开机启动模式又是设置为图形界面,所以一开LINUX就卡住了,进入不了命令行界面 ... [详细]
  • Go Cobra命令行工具入门教程
    本文介绍了Go语言实现的命令行工具Cobra的基本概念、安装方法和入门实践。Cobra被广泛应用于各种项目中,如Kubernetes、Hugo和Github CLI等。通过使用Cobra,我们可以快速创建命令行工具,适用于写测试脚本和各种服务的Admin CLI。文章还通过一个简单的demo演示了Cobra的使用方法。 ... [详细]
  • 本文讨论了在手机移动端如何使用HTML5和JavaScript实现视频上传并压缩视频质量,或者降低手机摄像头拍摄质量的问题。作者指出HTML5和JavaScript无法直接压缩视频,只能通过将视频传送到服务器端由后端进行压缩。对于控制相机拍摄质量,只有使用JAVA编写Android客户端才能实现压缩。此外,作者还解释了在交作业时使用zip格式压缩包导致CSS文件和图片音乐丢失的原因,并提供了解决方法。最后,作者还介绍了一个用于处理图片的类,可以实现图片剪裁处理和生成缩略图的功能。 ... [详细]
  • Centos7搭建ELK(Elasticsearch、Logstash、Kibana)教程及注意事项
    本文介绍了在Centos7上搭建ELK(Elasticsearch、Logstash、Kibana)的详细步骤,包括下载安装包、安装Elasticsearch、创建用户、修改配置文件等。同时提供了使用华为镜像站下载安装包的方法,并强调了保证版本一致的重要性。 ... [详细]
author-avatar
acChristina
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有