Table of Contents
1. 删除老版本MySQL
1.1 查看已安装的mysql版本并删除
1.2 删除数据文件
1.3 查看当前是否有mysql在运行
2. 源码安装MySQL5.6
2.1 编译
2.1.1 cmake
2.1.2 make && make install
2.2 安装
2.3 启动MySQL
2.4 修改root密码
Home Database Mysql Tutorial linux上源码安装MySQL详解_MySQL

linux上源码安装MySQL详解_MySQL

Jun 01, 2016 pm 01:02 PM
Source code

最近需要使用MySQL Fabric,这货是MySQL5.6.10之后才出现的utility。手头机器装的是MySQL5.1,所以需要先把旧版MySQL升级成5.6版本。之前没有玩过MySQL,所以这次稍微费了点事。在此,把过程记录下来,希望能给有需求的人提供一点帮助。下面我们就正式开始。

1. 删除老版本MySQL

其实删除老版MySQL是一件很简单的事,但是开始时候由于担心各个包的依赖会导致各种问题,亦步亦趋来得很慢。其实只需要做到这么几步就可以了:

1.1 查看已安装的mysql版本并删除

查看已安装的mysql版本:rpm -qa | grep -i mysql

只要将client/server两个rpm包卸载就可以,过程中可能会提示某个包的依赖,加上--nodeps即可。

1.2 删除数据文件

删除/etc/my.cnf以及安装目录/usr/local/mysql/(该目录位置是安装时指定的)下的数据文件。 rm -r /etc/my.cnf rm -rf /usr/local/mysql

1.3 查看当前是否有mysql在运行

这一步经常会被忽视掉,所以需要稍微注意下。若有则kill掉。使用命令:ps -fe | grep mysql查看。
经过上面的三个步骤,基本就可以把旧版mysql卸载掉了。其他遗留部分在后续安装新版mysql时,会提示有不兼容的情况,到时候再逐个删除即可。

2. 源码安装MySQL5.6

前提一:既然是源码安装,肯定要先下载一份MySQL源码了。这个大家根据自己的需求下载,在此就不赘述了。前提二:安装cmake。MySQL的编译是使用的cmake,所以需要提前安装好。这个过程也很简单,就不说了。上面的准备工作都OK之后,就开始正式安装的过程了。

2.1 编译

与linux上其他的工程一样,MySQL的编译也就是make/make install。

2.1.1 cmake

在代码路径下执行:
cmake ./ -DCMAKE_INSTALL_PREFIX=/usr/local/mysql  \
-DMYSQL_DATADIR=/usr/local/mysql/data             \
-DSYSCONFDIR=/etc                                 \
-DWITH_MYISAM_STORAGE_ENGINE=1                    \
-DWITH_INNOBASE_STO…
Copy after login
上面的编译参数,有几个在后续的安装过程中需要使用,在此说明一下。其他的可以不用管,直接复制即可。 DCMAKE_INSTALL_PREFIX:MySQL的安装路径,安装完成后就是MySQL的工作路径。
DMYSQL_DATADIR:MySQL的数据文件位置。
DSYSCONFDIR:MySQL的配置文件位置。

2.1.2 make && make install

这个用过linux的都知道吧。。到此,编译的过程就完成了。

2.2 安装

# cd /usr/local/mysql
# chown -R mysql:mysql .
# chown -R mysql:mysql ./data
# scripts/mysql_install_db --defaults-file=/etc/my.cnf
# cp support-files/my-default.cnf /etc/my.cnf
Copy after login
上面这些都是MySQL的配置过程,其中的路径必须和上面cmake的参数保持一致。其中mysql的配置文件/etc/my.cnf需要注意,下面是我的配置文件,基本保持这样就可以了。
[mysql]
socket = /tmp/mysqld.sock

[mysqld]
user = mysql
datadir = /usr/local/mysql/data
port=3306
Copy after login

2.3 启动MySQL

有三种方法可以启动MySQL,分别如下:
方法一:
# bin/mysqld_safe --defaults-file=/etc/my.cnf
方法二:
# bin/mysqld
方法三:
cp support-files/msql.server /etc/init.d/mysql
service mysql start
Copy after login
相信大家对第三种方法更熟悉,使用start|restart|stop来启动/重启/停止一个服务的操作,在linux中使用的十分广泛。我也习惯使用这种方法,但是在使用过程中发现一个情况。使用service mysql start时,如果服务启动失败,基本不会有什么错误log输出,所以想判断是什么原因导致的启动失败就比较困难。这时候推荐使用方法二来启动,它会将错误原因输出,对于勘误难说容易的多。 查看启动是否成功:ps -ef | grep mysql

2.4 修改root密码

# ./bin/mysqladmin -u root password
Copy after login
两遍输入密码即可。修改完密码之后,需要重启一下mysql。到此,MySQL从老版本升级的过程就完成了。
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Application practice of Python in software source code protection Application practice of Python in software source code protection Jun 29, 2023 am 11:20 AM

As a high-level programming language, Python language is easy to learn, easy to read and write, and has been widely used in the field of software development. However, due to the open source nature of Python, the source code is easily accessible to others, which brings some challenges to software source code protection. Therefore, in practical applications, we often need to take some methods to protect Python source code and ensure its security. In software source code protection, there are a variety of application practices for Python to choose from. Below are some common

How to display the source code of PHP code in the browser without being interpreted and executed? How to display the source code of PHP code in the browser without being interpreted and executed? Mar 11, 2024 am 10:54 AM

How to display the source code of PHP code in the browser without being interpreted and executed? PHP is a server-side scripting language commonly used to develop dynamic web pages. When a PHP file is requested on the server, the server interprets and executes the PHP code in it and sends the final HTML content to the browser for display. However, sometimes we want to display the source code of the PHP file directly in the browser instead of being executed. This article will introduce how to display the source code of PHP code in the browser without being interpreted and executed. In PHP, you can use

Website to view source code online Website to view source code online Jan 10, 2024 pm 03:31 PM

You can use the browser's developer tools to view the source code of the website. In the Google Chrome browser: 1. Open the Chrome browser and visit the website where you want to view the source code; 2. Right-click anywhere on the web page and select "Inspect" or press the shortcut key Ctrl + Shift + I to open the developer tools; 3. In the top menu bar of the developer tools, select the "Elements" tab; 4. Just see the HTML and CSS code of the website.

Can vue display source code? Can vue display source code? Jan 05, 2023 pm 03:17 PM

Vue can display the source code. The method for viewing the source code in Vue is: 1. Obtain Vue through "git clone https://github.com/vuejs/vue.git"; 2. Install dependencies through "npm i"; 3. Through " npm i -g rollup" to install rollup; 4. Modify the dev script; 5. Debug the source code.

A comprehensive guide to learning and applying golang framework source code A comprehensive guide to learning and applying golang framework source code Jun 01, 2024 pm 10:31 PM

By understanding the Golang framework source code, developers can master the essence of the language and expand the framework's functions. First, get the source code and become familiar with its directory structure. Second, read the code, trace the execution flow, and understand dependencies. Practical examples show how to apply this knowledge: create custom middleware and extend the routing system. Best practices include learning step-by-step, avoiding mindless copy-pasting, utilizing tools, and referring to online resources.

How to view the source code of tomcat in idea How to view the source code of tomcat in idea Jan 25, 2024 pm 02:01 PM

Steps to view tomcat source code in IDEA: 1. Download Tomcat source code; 2. Import Tomcat source code in IDEA; 3. View Tomcat source code; 4. Understand the working principle of Tomcat; 5. Precautions; 6. Continuous learning and updating ; 7. Use tools and plug-ins; 8. Participate in the community and contribute. Detailed introduction: 1. Download the Tomcat source code. You can download the source code package from the official website of Apache Tomcat. Usually these source code packages are in ZIP or TAR format, etc.

Golang framework source code analysis and optimization Golang framework source code analysis and optimization Jun 02, 2024 pm 04:54 PM

This article explores the source code analysis and optimization of the Go framework. The source code structure includes four main packages, involving core framework logic, request context, data binding and response rendering. Optimization techniques include: 1. Use routing trees to optimize route processing to significantly increase route lookup speed. 2. Use middleware for caching and compression to reduce server load and response time. 3. Avoid performing time-consuming operations in callbacks to maintain high responsiveness. 4. Enable logging and analyze slow requests to identify performance bottlenecks. 5. Update framework versions regularly to take advantage of the latest performance improvements.

PHP source code error: solving index error problem PHP source code error: solving index error problem Mar 10, 2024 am 11:12 AM

PHP source code error: To solve the index error problem, specific code examples are needed. With the rapid development of the Internet, developers often encounter various problems when writing websites and applications. Among them, PHP is a popular server-side scripting language, and its source code errors are one of the problems that developers often encounter. Sometimes, when we try to open the index page of a website, various error messages will appear, such as "InternalServerError", "Unde

See all articles