Install and configure MySQL in Linux

Source: Internet
Author: User

Install and configure MySQL in Linux

System: Ubuntu 16.04LTS

1 \ Download mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz from the official website

2 \ create a working group:

$su#groupadd mysql#useradd -r -g mysql mysql

3 \ create directory

#mkdir /usr/local/mysql#mkdir /usr/local/mysql/data

4 \ decompress mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz and copy it to/usr/local/mysql

#tar -zxvf mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz#cp -r /home/jieyamulu/mysql-5.7.18-linux-glibc2.5-x86_64/* /usr/local/mysql

5 \ modify the permissions of mysql users for files below mysql and Their subfolders. After modification, you can use ll to view the permissions.

Root @ Ice-***:/usr/local # chown-R mysql: mysql mysqlroot @ Ice -***: /usr/local # ll total usage 44drwxr-xr-x 11 root 4096 May 19 07:39. /drwxr-xr-x 11 root 4096 February 16 04:30 .. /drwxr-xr-x 2 root 4096 February 16 04:19 bin/drwxr-xr-x 2 root 4096 February 16 04:19 etc/drwxr-xr-x 2 root 4096 February 16 04:19 games/ drwxr-xr-x 2 root 4096 February 16 04:19 include/drwxr-xr-x 4 root 4096 February 16 04:23 lib/lrwxrwxrwx 1 root 9 March 29 14:11 man-> share/man/ drwxr-xr-x 10 mysql 4096 May 19 07:48 mysql/drwxr-xr-x 2 root 4096 February 16 04:19 sbin/drwxr-xr-x 8 root 4096 February 16 04:34 share/drwxr -xr-x 2 root 4096 February 16 04:19 src/root @ Ice -***: /usr/local # cd mysql/root @ Ice-***:/usr/local/mysql # ll total usage 64drwxr-xr-x 10 mysql 4096 May 19 07:48. /drwxr-xr-x 11 root 4096 May 19 07:39 .. /drwxr-xr-x 2 mysql 4096 May 19 07:48 bin/-rw-r -- 1 mysql 17987 May 19 07:48 COPYINGdrwxr-xr-x 2 mysql 4096 May 19 07:41 data/ drwxr-xr-x 2 mysql 4096 May 19 07:48 docs/drwxr-xr-x 3 mysql 4096 May 19 07:48 include/drwxr-xr-x 5 mysql 4096 May 19 07:48 lib/drwxr -xr-x 4 mysql 4096 May 19 07:48 man/-rw-r -- 1 mysql 2478 May 19 07:48 READMEdrwxr-xr-x 28 mysql 4096 May 19 07:48 share/drwxr- xr-x 2 mysql 4096 May 19 07:48 support-files/

6 \ modify (or create) the/etc/my. cnf configuration file

root@Ice-***:/usr/local/mysql# vim /etc/my.cnf [mysqld] basedir=/usr/local/mysql/datadir=/usr/local/mysql/data:wq

7 \ most critical Initialization

# cd /usr/local/mysql/root@Ice-***:/usr/local/mysql# ./bin/mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --initialize2017-05-19T00:15:46.529420Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).2017-05-19T00:15:47.066125Z 0 [Warning] InnoDB: New log files created, LSN=457902017-05-19T00:15:47.213711Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.2017-05-19T00:15:47.286951Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 4e958344-3c28-11e7-8334-c8d3ffd2db82.2017-05-19T00:15:47.292857Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.2017-05-19T00:15:47.294758Z 1 [Note] A temporary password is generated for root@localhost: YjaotQk*2ew4

Remember the initial password
There may be many problems, such:

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

Dependency package missing

Solution:sudo apt-get install libaio-dev

It may be that the previous steps are incorrect, resulting in insufficient permissions to operate the data file. according to the steps, the initialization should be successful when there is nothing to install (there is a prompt). The Warning is worth noting that Gtid table is not ready to be used. table 'mysql. gtid_executed 'cannot be opened. if you have time, you can check what is going on. This ignore will not affect you.

8 \ do not worry about starting, but it cannot be started now. Execute the code and change the files except the data folder in mysql to the root permission.

root@Ice-***:/usr/local/mysql# chown -R root .root@Ice-***:/usr/local/mysql# chown -R mysql data

9 \ Start

root@Ice-***:/usr/local/mysql# bin/mysqld_safe --user=mysql &

Press ENTER

root@Ice-***:/usr/local/mysql# /usr/local/mysql/bin/mysql -uroot -pEnter password: Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 3Server version: 5.7.18Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> show databases;ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.mysql> 

10 \ Reset Password

mysql> SET PASSWORD = PASSWORD('newpasswd');Query OK, 0 rows affected, 1 warning (0.00 sec)mysql> show databases;+--------------------+| Database      |+--------------------+| information_schema || mysql       || performance_schema || sys        |+--------------------+4 rows in set (0.00 sec)mysql> quitBye

11 \ set startup

root@Ice-***:/usr/local/mysql# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqldroot@Ice-***:/usr/local/mysql# chmod 755 /etc/init.d/mysqld

12 \ install mysql-server and mysql-client

root@Ice-***:~# apt-get install mysql-serverroot@Ice-***:~# apt-get install mysql-clientroot@Ice-***:~# apt-get install libmysqlclient-devE: Sub-process /usr/bin/dpkg returned an error code (1)

Solution:

1. $ sudo mv/var/lib/dpkg/info/var/lib/dpkg/info_old // rename the info folder.
2. $ sudo mkdir/var/lib/dpkg/info // create a new info folder.
3. $ sudo apt-get update,
$ Apt-get-f install // fix the dependency tree
4. $ sudo mv/var/lib/dpkg/info/*/var/lib/dpkg/info_old // After performing the previous operation, some files will be generated in the new info folder, move all these files to the info_old folder.
5. $ sudo rm-rf/var/lib/dpkg/info // Delete the info folder you created
6. $ sudo mv/var/lib/dpkg/info_old/var/lib/dpkg/info // rename the previous info folder

Finally, if it is Ubuntu, Chinese characters may not be inserted into the table, and Chinese characters cannot be queried from the table ..

Solution:

Disable Database Service

service mysql stop~$ sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf

Add a character_set_server = utf8 line under [mysqld]
Configuration File CIDR Block:

[Mysqld] # * Basic Settings # user = mysqlpid-file =/var/run/mysqld. pidsocket =/var/run/mysqld. sockport = 3306 basedir =/usrdatadir =/var/lib/mysqltmpdir =/tmplc-messages-dir =/usr/share/mysqlcharacter_set_server = utf8 is the same line. It was not found, to manually add! Skip-external-locking #


Copy the above file to/etc/mysql/my. cnf

~$ sudo cp /etc/mysql/mysql.conf.d/mysqld.cnf /etc/mysql/my.cnf

Restart Database Service

~$ /etc/init.d/mysql restart

If you can view the character set, the result is as follows.

mysql> show variables like 'collation_%';+----------------------+-----------------+| Variable_name    | Value      |+----------------------+-----------------+| collation_connection | utf8_general_ci || collation_database  | utf8_general_ci || collation_server   | utf8_general_ci |+----------------------+-----------------+3 rows in set (0.00 sec)mysql> show variables like 'character_set_%';+--------------------------+----------------------------+| Variable_name      | Value           |+--------------------------+----------------------------+| character_set_client   | utf8            || character_set_connection | utf8            || character_set_database  | utf8            || character_set_filesystem | binary           || character_set_results  | utf8            || character_set_server   | utf8            || character_set_system   | utf8            || character_sets_dir    | /usr/share/mysql/charsets/ |+--------------------------+----------------------------+8 rows in set (0.01 sec)

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.