Ubuntu install MySQL steps and configuration summary

Source: Internet
Author: User

Because you often have to do some development work in the environment of Ubuntu Linux. There are many times when MySQL-related development work is involved. So the whole process to do a collation, in order to facilitate the installation of the configuration again at the time of reference, but also hope to let the novice less go a little detour.

In fact, the main thing to do is to install a MySQL server on the Ubuntu machine, and then you need to configure specific accounts and permissions to execute some SQL scripts to create an environment that contains complete data. Start Now:

1. Installation

If we enter the following command in an Ubuntu system that does not have MySQL installed: MySQL, the system will give the following prompt:

SQL code
    1. The program ' MySQL ' was currently not installed. You can install it by typing:
    2. sudo apt-get install mysql-client-core-5.5

In fact, when we install MySQL, we can choose to install the server or client, if it is only installed with the client side, to connect to the server side to install servers to access. The client provides the ability to interact with SQL scripts and to connect to a particular MySQL server. Because we need to install the server, we can use the following command, and also the client is included in the installation.

SQL code
    1. sudo apt-get install Mysql-server

You will be prompted to enter the root account password during the installation process. Root is the Administrator role in the MySQL system and has the highest permissions.

After entering your password, you will be prompted to confirm your password again, such as:

After you confirm the password, the system automatically completes the subsequent installation process.

2. Login with Root

After the installation process, we can log into MySQL server. MySQL is not allowed to log on anonymously by default. If we enter the following command: MySQL, you may get the following error message:

SQL code
    1. ERROR 1045 (28000): Access denied for user ' Frank ' @' localhost ' (using password: NO)

Now that we have specified the root user's password, you can log in using the following command:

SQL code
    1. Mysql-u root-p

The-u option is used to specify the logged-on user, followed by root to sign in with the root account. The-p option indicates login with password authentication.

After entering the previous command, you will be prompted to enter the password, if correct, you can enter the system.

3. Create a new user

In most cases, if we are going to do some development work with MySQL, we will not use the root account directly. The general root account is used for some system administration and maintenance work, and because root privileges are too high. If there is a problem with the MySQL system, it can easily cause all data corruption. So we need to create a specific user, by root, to assign certain permissions to it. This way, even if there is a problem with the account, the loss may be only within the scope of the account authority, not the overall damage.

For example, we want to create a new user, and set the user's access password, after logging into the system as the root user, execute the following command:

SQL code
    1. Create user ' Frank ' @' localhost ';
Java code
    1. Set password for ' Frank ' @' localhost ' = password (' ABCDEFG ');

The previous two commands created the user frank and set the user's password separately. For the first command, because the user is running on the local ' localhost ' instance, it needs to be specified as the ' username ' @ ' instance name ' style. If we want to set the character password, we need to use password ("), and then specify the password in the parentheses parameter later. As in this example, the password is ' ABCDEFG '.

In this way, we create a user and specify his password. Later, we need to specify the resources to assign permissions. Suppose we create a database: SampleDb.

Java code
    1. Create Database SampleDb;
4. Configure new user Permissions

Let's say we need to give all of SampleDb's permissions to the newly created user frank, we need to execute the following command:

SQL code
    1. Grant all privileges on sampledb.* to ' Frank ' @' localhost ';

This is the simplest way to set permissions, which means that all access rights to the database sampledb are given to the user frank. If finer-grained control is required, different access operations and different parts of the database need to be considered.

5. Execute the Script

After we have configured the user, we may need to execute some SQL scripts. There are several ways to execute a script, one that is not logged into MySQL server. Typical execution is as follows:

Java code
    1. shell> MySQL db_name < text_file
    2. shell> MySQL db_name-u username-p < text_file

These two approaches are performed based on both user authentication and non-authentication methods.

In the case of logging into MySQL, you can do it in a simpler way:

SQL code
    1. Mysql> source file_name
    2. mysql> \. file_name

Summarize:

The process of installing and configuring MySQL is a bit of a hassle, and if you get used to the manual configuration under Windows, you're not used to it. So summarize, for reference.

Ubuntu install MySQL steps and configuration summary

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.