Install mysql in linux [practice edition] And linuxmysql practice Edition

Source: Internet
Author: User
Tags mysql commands

Install mysql in linux [practice edition] And linuxmysql practice Edition

[Environment and file version]

Red hat linux v6.2

Mysql linux x86-x64 v5.6

[Prepare required files]

First, go to the official website to download the linux version of mysql. You can select an appropriate version for the installed operating system.

Decompress the file to a directory, such as/usr/local/, and rename it mysql. Make sure that all the final files are in the/usr/local/mysql/directory. You also need to locate the directory when using the command line. Subsequent operations are completed in this directory.

 

[Initialize database files]

Then copy the support-files/my-default.cnf to the current directory, name it my. cnf, and modify the content as follows:

[Mysqld]

Skip-name-resolve # skip table scan to speed up the execution tree of mysql

Lower_case_table_names = 1 # All table names are in lower case

Datadir =/usr/local/mysql/data/# Set the data file storage location

Socket =/usr/local/mysql. sock

User = mysql

Character-set-server = utf8 # set the server character set to prevent Chinese garbled characters

# Disabling symbolic-links isrecommended to prevent assorted security risks

Symbolic-links = 0

 

[Mysqld_safe]

Log-error =/usr/local/mysql/log/mysqld. log # Note: manually create the log directory here.

Pid-file =/usr/local/mysql/mysqld. pid

 

Then execute the database initialization script file:

./Scripts/mysql_install_db -- defaults-file = my. cnf # The following parameter indicates using my. cnf defined in the previous step to initialize the database.

 

After several seconds, you can check the data directory to add the mysql directory and other files. At this time, mysql Initialization is complete, but now mysql is not a service form, and cannot be started using service xxx start. However, it can be started in./bin/mysqld_safe & mode.

Note: The command for manually starting mysql:./bin/mysqld_safe & # Check the reason for using mysqld_safe.

Command for manually stopping mysql:./bin/mysqladmin-h127.0.0.1 shutdown # Note: Do not use localhost whenever possible, because sometimes, due to system reasons, using localhost will prompt that mysql cannot be connected.

Manually stop mysql command 2: pkill mysql # Kill all processes whose names contain mysql, clean:-D

I will attach some other practical mysql commands in linux.

[Register mysql as a system service]

If you want mysql to start as a service or set mysql to start up, perform the following steps.

Set mysql. server copy to/etc/rc. d/init. d/, and rename it mysql (if you do not suspect mysql. if the server name is long, you can choose not to rename it:-D, and the file name is the service name ).

You can use service mysql start to start mysql (if you manually started mysql in the previous step, this step will prompt that mysql has been started ).

Of course, other Commands include service mysql stop/restart/status.

[Set mysql startup]

At this time, mysql has been registered as a service. If you need to start up, you need to perform two steps.

First, add mysql to the boot list:

Chkconfig -- add mysql

Then set it to boot:

Chkconfig mysql on

In this way, mysql will start up.

To disable startup, you can:

Chkconfig mysql off

Check whether mysql is started upon startup:

Chkconfig -- list mysql

Check whether mysql listening is on the listening port (3306 by default ):

Netstat-lt | grep mysql

[Mysql user name and remote Logon Settings]

How to install and start mysql above. After the first installation of mysql, you also need to set the user name, password, and remote login.

By default, mysql only has the root user, and the password is blank. You are not allowed to log on to another machine on this machine. To set a password for the root user and allow remote logon, perform this operation.

 

First, log on to mysql on the mysql-installed machine:

Mysql-uroot-h127.0.0.1

Run the following command:

Grant all privilegeson *. * to root @ '%' identified by '123 ';

If you do not need to set a password, the identified by '20160301' can be omitted.

In this way, you can remotely connect to mysql using tools such as navicat and perform other operations.

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.