Home Database Mysql Tutorial Ubuntu12.04下安装Mysql

Ubuntu12.04下安装Mysql

Jun 07, 2016 pm 03:35 PM
mysql under personal Install

下面就个人这几天在ubunt12.04下安装mysql做一个总结: 在linux下安装mysql有三种方式:第一种以rpm的二进制文件分个安装,第二种是自己编译源码后安装,最后一种是以二进制tar.gz文件来安装。 这三种中,由于最后一种是统一的整体文件,个人感觉最简单,故

下面就个人这几天在ubunt12.04下安装mysql做一个总结:

在linux下安装mysql有三种方式:第一种以rpm的二进制文件分个安装,第二种是自己编译源码后安装,最后一种是以二进制tar.gz文件来安装。

这三种中,由于最后一种是统一的整体文件,个人感觉最简单,故本文将采用此方式来进行安装:

首先到mysql的下载中心上下载最新的tar.gz包:

1.在浏览器中输入http://www.mysql.com/downloads/,进入mysql的下载中心,在这里有使用mysql开发的一些工具,包括mysql的驱动,数据库以及图形开发工具MySQL Workbench等。在这里我们选择MySQL Community Server链接,进入mysql 数据库服务器的下载:

Ubuntu12.04下安装Mysql

如上,点击“MySQL Community Server”链接进入下载页面,接着选择myql的平台,选择Linux - Generic平台:

Ubuntu12.04下安装Mysql

然后在其中选择二进制tar.gz文件形式的文件进行下载:

Ubuntu12.04下安装Mysql

选择32位或64位的下载,这里选择32位的,下载后得到文件mysql-5.5.28-linux2.6-i686.tar.gz,然后将其解压,并重命名为mysql,使用mv命令将其移到/usr/local目录下:

sudo mv ~/下载/mysql  /usr/local
Copy after login
则得到的目录结构如下:

Ubuntu12.04下安装Mysql

提示:其中文本文件INSTALL-BINARY详细的记录了mysql在Linux下的安装方法,英文好的同鞋可以直接的查看。

将上面的做好了后,我们现在就可以进入mysql的安装了,根据INSTALL-BINARY文件的描述,可知mysql默认的安装目录就是在/usr/local/mysql,这就是上面为什么我们要将其移动在/uer/local下的原因;如果在你的机器上以前安装有老板本的mysql,需要先将它的文件删除,同时注意删除老板本的etc/my.cnf文件和/etc/mysql目录,这两个文件控制的是mysql的一些配置属性。

按上面的记叙我可以知,先要创建的一个名为mysql的用户组和用户,来承载mysql数据库的运行,使用如下命令:

创建用户组:

sudo groupadd mysql
Copy after login
在创建的用户组中创建一个用户:
sudo useradd -r -g mysql mysql
Copy after login
这里使用sudo命令是确保以root权限执行此命令,如果你登入本机的用户是root用户,则直接的使用groupadd和useradd命令。

题外话:对应删除用户组及用户的命令是groupdel和userdel。

接着进入mysql目录,修改mysql目录的拥有者,为mysql用户:

进入目录:

cd /usr/local/mysql
Copy after login

修改目录的拥有者:

sudo chown -R mysql .
sudo chgrp -R mysql .
Copy after login

这里的点“.”代表的就是当前目录,选项-R表示递归当前目录及其子目录。

现在真正的进入主题,安装mysql,执行命令:

sudo scripts/mysql_install_db --user=mysql
Copy after login
其实,这一步正真的目地就是生成一些mysql数据库运行的系统数据库。

注意:在ubuntu 12.04下安装mysql 5.5.28版本执行此命令时,会提示如下错误的信息

./bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory

这说明还要安装一个libaio的依赖库,执行如下命令:

sudo apt-get install libaio-dev
Copy after login
安装完libaio后,继续执行“sudo  scripts/mysql_install_db --user=mysql”命令来进行安装。

执行完上面的命令后,其实就已经完成了mysql的安装,但为了数据库的安全,可以将mysql目录的拥有者改为root用户,并将生成的系统依赖数据赋给mysql用户,执行如下命令:

chown -R root .
chown -R mysql data
Copy after login

安装好mysql后,就可以试着启动它,使用如下命令:

sudo ./support-files/mysql.server start
Copy after login
同样重启和停止,只需要将上面命令的start改为restart或stop。

启动完mysql后,我们接着可以测试一下,使用“./bin/mysql”命令来进入mysql数据库的控制台,执行SQL命令。

为了数据库的安全我们需要为数据库访问设置密码,可以执行如下命令,将mysql的配置文件安装到/etc目录下:

sudo cp support-files/my-medium.cnf /etc/my.cnf
Copy after login
然后更改/etc/my.cnf文件,在[client]段下,取消password注释,并将your_password改为你的密码。

这样设置好后,进入mysql的控制台,则需要使用如下命令:

sudo ./bin/mysql -uroot -p
Copy after login

提示输入密码后,就可以进入控制台了。


最后:

上面介绍的这么多,总结mysql的安装实际上只需执行“sudo ./scripts/mysql_install_db --user=系统用户名“这一条命令,这里设置的系统用户可以直接的使用当前登入系统用户,在linux中查看当前用户的命令是:

who am i
Copy after login
同时,如果不想将mysql安装到/usr/local/mysql下,可以使用如下命令将你指定的目录与/usr/local/mysql目录关联:
ln -s <mysql> /usr/local/mysql</mysql>
Copy after login
或修改/support-files/mysql.server文件,为其指定basedir和datadir两个参数,如:
basedir=<mysql>
datadir=<mysql>/data</mysql></mysql>
Copy after login

在启动mysql时,还可以使用如下命令:

sudo ./bin/mysqld_safe --user=mysql &
Copy after login
启动后,修改密码也可以使用如下命令:
sudo ./bin/mysqladmin -u root -p password '新密码'
Copy after login

提示输入旧数据库的密码后,密码才变更为新密码

为了确保数据库中支持中文,可以修改/etc/my.cnf文件:

在[client]段下添加

default-character-set = utf8
Copy after login
在[mysqld]段下添加
character_set_server = utf8
Copy after login

安装好mysql后,就可以安装mysql的图形化客服端MySQL Workbench了,可以到http://www.mysql.com/downloads/workbench/下选择合适的版本下载,在上面有ubuntu下的版本,下载后的文件为BED格式,双击后可以直接安装十分方便。

如果在安装好MySQL Workbench后,出现运行mysql.server start无法启动的情况,可以查看一下,是否存在/etc/mysql目录,如果有要将其删除;同时还要检查/etc/my.cnf文件的内容。

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)

MySQL: An Introduction to the World's Most Popular Database MySQL: An Introduction to the World's Most Popular Database Apr 12, 2025 am 12:18 AM

MySQL is an open source relational database management system, mainly used to store and retrieve data quickly and reliably. Its working principle includes client requests, query resolution, execution of queries and return results. Examples of usage include creating tables, inserting and querying data, and advanced features such as JOIN operations. Common errors involve SQL syntax, data types, and permissions, and optimization suggestions include the use of indexes, optimized queries, and partitioning of tables.

MySQL's Place: Databases and Programming MySQL's Place: Databases and Programming Apr 13, 2025 am 12:18 AM

MySQL's position in databases and programming is very important. It is an open source relational database management system that is widely used in various application scenarios. 1) MySQL provides efficient data storage, organization and retrieval functions, supporting Web, mobile and enterprise-level systems. 2) It uses a client-server architecture, supports multiple storage engines and index optimization. 3) Basic usages include creating tables and inserting data, and advanced usages involve multi-table JOINs and complex queries. 4) Frequently asked questions such as SQL syntax errors and performance issues can be debugged through the EXPLAIN command and slow query log. 5) Performance optimization methods include rational use of indexes, optimized query and use of caches. Best practices include using transactions and PreparedStatemen

Why Use MySQL? Benefits and Advantages Why Use MySQL? Benefits and Advantages Apr 12, 2025 am 12:17 AM

MySQL is chosen for its performance, reliability, ease of use, and community support. 1.MySQL provides efficient data storage and retrieval functions, supporting multiple data types and advanced query operations. 2. Adopt client-server architecture and multiple storage engines to support transaction and query optimization. 3. Easy to use, supports a variety of operating systems and programming languages. 4. Have strong community support and provide rich resources and solutions.

How to connect to the database of apache How to connect to the database of apache Apr 13, 2025 pm 01:03 PM

Apache connects to a database requires the following steps: Install the database driver. Configure the web.xml file to create a connection pool. Create a JDBC data source and specify the connection settings. Use the JDBC API to access the database from Java code, including getting connections, creating statements, binding parameters, executing queries or updates, and processing results.

How to start mysql by docker How to start mysql by docker Apr 15, 2025 pm 12:09 PM

The process of starting MySQL in Docker consists of the following steps: Pull the MySQL image to create and start the container, set the root user password, and map the port verification connection Create the database and the user grants all permissions to the database

MySQL's Role: Databases in Web Applications MySQL's Role: Databases in Web Applications Apr 17, 2025 am 12:23 AM

The main role of MySQL in web applications is to store and manage data. 1.MySQL efficiently processes user information, product catalogs, transaction records and other data. 2. Through SQL query, developers can extract information from the database to generate dynamic content. 3.MySQL works based on the client-server model to ensure acceptable query speed.

How to install mysql in centos7 How to install mysql in centos7 Apr 14, 2025 pm 08:30 PM

The key to installing MySQL elegantly is to add the official MySQL repository. The specific steps are as follows: Download the MySQL official GPG key to prevent phishing attacks. Add MySQL repository file: rpm -Uvh https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm Update yum repository cache: yum update installation MySQL: yum install mysql-server startup MySQL service: systemctl start mysqld set up booting

Laravel Introduction Example Laravel Introduction Example Apr 18, 2025 pm 12:45 PM

Laravel is a PHP framework for easy building of web applications. It provides a range of powerful features including: Installation: Install the Laravel CLI globally with Composer and create applications in the project directory. Routing: Define the relationship between the URL and the handler in routes/web.php. View: Create a view in resources/views to render the application's interface. Database Integration: Provides out-of-the-box integration with databases such as MySQL and uses migration to create and modify tables. Model and Controller: The model represents the database entity and the controller processes HTTP requests.

See all articles