Install MySQL under Ubuntu

Source: Internet
Author: User
Tags gz file mysql download mysql gui

in the There are three ways to install MySQL under Linux: the first binary files are installed in RPM, the second is to install them after compiling the source code, and the last is to install them in binary tar.gz files.

Of these three kinds, because the last one is a unified overall file, the personal feeling is the simplest, so this article will be used in this way to install:

start by downloading the latest tar.gz package to MySQL Download Center:

1. Enter http://www.mysql.com/downloads/in the browser, go to MySQL Download Center, there are some tools to use MySQL development, including MySQL driver, database and graphics development tools MySQL workbench and so on. Here we select the MySQL Community server link to access the MySQL database server download:

as above, click on the "MySQL Community Server" link to enter the download page, then select MYQL Platform, select the Linux-generic platform:

then select a file in the form of a binary tar.gz file to download:

Select 32-bit or 64-bit download, here choose 32-bit, download and get the file mysql-5.5.28-linux2.6-i686.tar.gz, then unzip it, rename it to MySQL, use the MV command to move it to/usr/ In the local directory:

sudo mv ~/download/mysql/usr/local

The resulting directory structure is as follows:

after the above is done, we can now enter the MySQL installation, according to the description of the Install-binary file, the MySQL default installation directory is the/usr/local/mysql, this is the above why we want to move it in/ Uer/local reasons; If you have previously installed the owner of MySQL on your machine, you need to first delete its files, but also pay attention to delete the owner of the etc/my.cnf file and/etc/mysql directory, these two files control the MySQL configuration properties.

According to the above narrative I can know, first to create a user group named MySQL and users, to host the MySQL database run, using the following command:

To create a user group:

sudo groupadd MySQL

Create a user in the created user group:

sudo useradd-r-g MySQL MySQL

The sudo command is used here to ensure that this command is executed with root, and if the user who is logged in to the computer is the root user, use the Groupadd and Useradd commands directly.

Off -topic: the commands that correspond to deleting user groups and users are Groupdel and Userdel.

then go to MySQL directory, modify the MySQL directory owner, for the MySQL user:

Enter directory:

Cd/usr/local/mysql

Modify the owner of the directory:

sudo chown-r MySQL.

sudo chgrp-r MySQL.

Here's the point "." Represents the current directory, and the option-R represents the recursive current directory and its subdirectories.

now really go into the theme, install MySQL, execute the command:

sudo scripts/mysql_install_db--user=mysql

In fact, this step is really the goal is to generate some MySQL database running the system database.

Note: in Install MySQL 5.5.28 version under Ubuntu 12.04 When you execute this command, you are prompted with the following error message:

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

This means that you will also install a Libaio dependent library and execute the following command:

sudo apt-get install Libaio-dev

After installing Libaio, continue with the sudo scripts/mysql_install_db--user=mysql command to install.

after executing the above command, actually completed the installation of MySQL, but for the security of the database, you can change the owner of the MySQL directory to the root user, and the generated system dependent data to the MySQL user, execute the following command:

Chown-r Root.

Chown-r MySQL Data

After you have installed MySQL, you can try to start it by using the following command:

sudo./support-files/mysql.server start

to restart and stop again, simply change the start of the above command to restart or stop.

After starting MySQL, we can then test and use the "./bin/mysql" command to access the MySQL database's console and execute the SQL command.

For database Security We need to set the password for database access, you can execute the following command to install the MySQL configuration file in the/etc directory:

sudo cp support-files/my-medium.cnf/etc/my.cnf

then change the/etc/my.cnf file, under [client], cancel the password comment and change the your_password to your password.

once this is set up, go to the MySQL console and you will need to use the following command:

sudo./bin/mysql-uroot-p

At last:

As described above, the summary MySQL installation actually simply executes "sudo./scripts/mysql_install_db--user= system username" This command, the system user set here can directly use the currently logged in System user, The commands to view the current user in Linux are:

Who am I

also, if you do not want to install MySQL under/usr/local/mysql, you can associate the directory you specify with the/usr/local/mysql directory using the following command:

Ln-s <mysql Catalogue >/usr/local/mysql

or modify the <mysql directory >/support-files/mysql.server file to specify Basedir and datadir two parameters, such as:

Basedir=<mysql Catalogue >

Datadir=<mysql Directory >/data

When you start MySQL, you can also use the following command:

sudo./bin/mysqld_safe--user=mysql &

After startup, you can also use the following command to change the password:

sudo./bin/mysqladmin-u root-p password ' new password '

when prompted to enter the password for the old database , the password is changed to the new password.

to ensure that Chinese is supported in the database, you can modify the/etc/my.cnf file:

in the Added under [Client] segment

Default-character-set = UTF8

in the [MYSQLD] section under Add

Character_set_server = UTF8

After installing MySQL, you can install MySQL GUI Workbench, you can choose the right version of http://www.mysql.com/downloads/workbench/under the download, In the above version of Ubuntu , after downloading the file for bed format, double-click can be directly installed very convenient.

If you are installing a good After MySQL Workbench, when running Mysql.server start fails to start, you can see if there is a/etc/mysql directory, if you want to delete it, and also check the contents of the/etc/my.cnf file.

Install MySQL under Ubuntu

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.