Day1-MySQL Installation Method Introduction, day1-mysql Installation Method

Source: Internet
Author: User

Day1-MySQL Installation Method Introduction, day1-mysql Installation Method

Windows Version

1. Download

1 MySQL Community Server 5.7.162  3 http://dev.mysql.com/downloads/mysql/

2. Decompress

If you want MySQL to be installed in a specified directory, move the decompressed folder to the specified directory, such as: C: \ mysql-5.7.16-winx64

3. Initialization

The decompressed bin directory of MySQL contains a large number of executable files. Run the following command to initialize the data:

1 cd c:\mysql-5.7.16-winx64\bin2  3 mysqld --initialize-insecure

4. Start the MySQL Service

Run the command to start the MySQL Service

1 # enter the executable file directory 2 cd c: \ mysql-5.7.16-winx64 \ bin3 4 # Start MySQL Service 5 mysqld

5. Start the MySQL client and connect to the MySQL Service

Because the [mysqld -- initialize-insecure] command is used during initialization, it does not set a password for the root account by default.

1 # enter the executable file directory 2 cd c: \ mysql-5.7.16-winx64 \ bin3 4 # connect to MySQL Server 5 mysql-u root-p6 7 # prompt enter the password, press ENTER

Enter the press Enter:

So far, the MySQL server has been installed successfully and the client can be connected. To operate MySQL later, you only need to repeat steps 4 and 5 above. However, repeated steps 4 and 5 are cumbersome to enter the executable file directory. To facilitate future operations, you can perform the following operations.

A. Add Environment Variables

Add the MySQL executable file to the environment variable to execute the command.

Right-click the computer and choose Properties> advanced system Settings> advanced environment variables> Path in the second content box. one row, double-click to append the bin directory path of MySQL to the variable value, and separate it with;. For example, C: \ Program Files (x86) \ Parallels Tools \ Applications; % SystemRoot % \ system32; % SystemRoot % \ System32 \ Wbem; % SYSTEMROOT % \ System32 \ WindowsPowerShell \ v1.0 \; C: \ Python27; C: \ Python35; c: \ mysql-5.7.16-winx64 \ bin

In this way, you only need:

1 # Start the MySQL service, input 2 mysqld3 4 on the terminal # connect to the MySQL service, and enter 5 mysql-u root-p on the terminal

B. Create the MySQL service as a windows Service

Some problems have been solved in the previous step, but they are not thorough enough, because the current shard will be hang when the MySQL server is started in mysqd, so you can solve this problem by setting it:

1 # create a Windows Service for MySQL, execute this command on the terminal: 2 "c: \ mysql-5.7.16-winx64 \ bin \ mysqld" -- install3 4 # Remove the Windows Service for MySQL, run this command on the terminal: 5 "c: \ mysql-5.7.16-winx64 \ bin \ mysqld" -- remove

After registering as a service, you only need to execute the following command to start and close the MySQL service later:

1 # start MySQL Service 2 net start mysql3 4 # disable MySQL Service 5 net stop mysql

 

Linux version

Install mysql using a Binary Package

 

Binary Package name

mysql-5.5.49-linux2.6-x8.6_64.tar.gz 

Add users and groups

groupadd mysqluseradd -s /sbin/nologin -g mysql -M mysqltail -1 /etc/passwdid mysql

Start MySQL Installation

1 [root @ template] # mkdir-p/home/oldboy/tools 2 [root @ template] # cd/home/oldboy/tools 3 [root @ template tools] # wget http://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.49-linux2.6-x86_64.tar.gz 4 [root @ template tools] # tar xf mysql-5.5.49-linux2.6-x86_64.tar.gz 5 [root @ template tools] # mkdir-p/application/6 [root @ template tools] # mv mysql-5.5.49-linux2.6-x86_64/application/mysql-5.5.49 7 [root @ template tools] # ln-s/application/mysql-5.5.49 // application/mysql 8 [root @ template tools] # ls-l/application/mysql 9 lrwxrwxrwx 1 root 26 october 27 10:28/application/mysql->/application/mysql-5.5.49/10 11 [root @ template tools] # cd/application/mysql/12 [root @ template mysql] # ls-l support -files /*. cnf13-rw-r -- 1 7161 wheel 4691 March 1 2016 support-files/my-huge.cnf14-rw-r -- 1 7161 wheel 19759 March 1 2016 support-files/my-innodb-heavy-4G.cnf15-rw- r -- 1 7161 wheel 4665 March 1 2016 support-files/my-large.cnf16-rw-r -- 1 7161 wheel 4676 March 1 2016 support-files/my-medium.cnf17-rw-r -- 1 7161 wheel 2840 March 1 2016 support-files/my-small.cnf18 19 # copy my. cnf configuration file 20 [root @ template mysql] #/bin/cp support-files/my-small.cnf/etc/my. cnf21 [root @ template mysql] # mkdir-p/application/mysql/data22 [root @ template mysql] # chown-R mysql. mysql/application/mysql/
View Code

Initialize Database

 1 [root@template mysql]# /application/mysql/scripts/mysql_install_db --basedir=/application/mysql --datadir=/application/mysql/data --user=mysql 2 Installing MySQL system tables... 3 161027 10:30:22 [Note] /application/mysql/bin/mysqld (mysqld 5.5.49) starting as process 1958 ... 4 OK 5 Filling help tables... 6 161027 10:30:23 [Note] /application/mysql/bin/mysqld (mysqld 5.5.49) starting as process 1965 ... 7 OK 8  9 To start mysqld at boot time you have to copy10 support-files/mysql.server to the right place for your system11 12 PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !13 To do so, start the server, then issue the following commands:14 15 /application/mysql/bin/mysqladmin -u root password 'new-password'16 /application/mysql/bin/mysqladmin -u root -h template.com password 'new-password'17 18 Alternatively you can run:19 /application/mysql/bin/mysql_secure_installation20 21 which will also give you the option of removing the test22 databases and anonymous user created by default.  This is23 strongly recommended for production servers.24 25 See the manual for more instructions.26 27 You can start the MySQL daemon with:28 cd /application/mysql ; /application/mysql/bin/mysqld_safe &29 30 You can test the MySQL daemon with mysql-test-run.pl31 cd /application/mysql/mysql-test ; perl mysql-test-run.pl32 33 Please report any problems at http://bugs.mysql.com/
View Code

Add database files

1 [root@template mysql]# cp support-files/mysql.server  /etc/init.d/mysqld2 [root@template mysql]# chmod +x /etc/init.d/mysqld3 [root@template mysql]# ll /etc/init.d/mysqld 4 -rwxr-xr-x 1 root root 10880 Oct 27 10:31 /etc/init.d/mysqld

The default binary path is/usr/local/mysql.

1 [root@template mysql]# sed -i 's#/usr/local/mysql#/application/mysql#g' /application/mysql/bin/mysqld_safe /etc/init.d/mysqld

Start mysql database

1 [root@template mysql]# /etc/init.d/mysqld start2 Starting MySQL.. SUCCESS! 

Check whether the mysql database is started

1 [root@template mysql]# netstat -lntup|grep mysql2 tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      2224/mysqld       

Set mysql to start automatically

1 [root@template mysql]# chkconfig --add mysqld2 [root@template mysql]# chkconfig mysqld on3 [root@template mysql]# chkconfig --list mysqld4 mysqld          0:off   1:off   2:on    3:on    4:on    5:on    6:off

Configure auto-start upon startup

1 echo "#mysql start by huzhihua at 2016-10-27" >>/etc/rc.local 2 echo "/etc/init.d/mysqld start" >>/etc/rc.local 3 4 [root@template mysql]# tail -2 /etc/rc.local 5 #mysql start by huzhihua at 2016-10-276 /etc/init.d/mysqld start

Configure the global usage path of the mysql Command

1 [root@template mysql]# echo 'export PATH=/application/mysql/bin:$PATH' >>/etc/profile2 [root@template mysql]# tail -1 /etc/profile3 export PATH=/application/mysql/bin:$PATH4 [root@template mysql]# source /etc/profile5 [root@template mysql]# echo $PATH6 /application/mysql/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin

Log on to mysql

Three other logon methods:

1 mysql-uroot-p, 2 mysql-uroot 3 mysql-uroot-p 'oldboy123 '4 5 [root @ template mysql] # mysql 6 Welcome to the MySQL monitor. commands end with; or \ g. 7 Your MySQL connection id is 1 8 Server version: 5.5.49 MySQL Community Server (GPL) 9 10 Copyright (c) 2000,201 6, Oracle and/or its affiliates. all rights reserved.11 12 Oracle is a registered trademark of Oracle Corporation and/or its13 affiliates. other names may be trademarks of their respective14 owners.15 16 Type 'help; 'or' \ H' for help. type '\ C' to clear the current input statement.17 18 mysql> exit # exit

 

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.