How to Install MySQL on CentOS 7

Source: Internet
Author: User
Tags mysql client mysql commands mysql in mysql manual php mysql perl script strong password fully qualified domain name

  • How to Install MySQL on CentOS 7

    Updated Thursday, August 27th, by Linode

    Use promo codeDOCS10For $ credit to a new account. Contribute on GitHub

    View Project | View File | Edit File

    MySQL is a popular database management system used for Web and server applications. However, MySQL is no longer in CentOS's repositories and MariaDB has become the default database system offered. MariaDB is considered a drop-in replacement for MySQL and would are sufficient if you just need a database system in genera L. See we MariaDB in CentOS 7 guide for installation instructions.

    If you nonetheless prefer MySQL, this guide would introduce how to install, configure and manage it on a Linode running Cen TOS 7.

    Large MySQL databases can require a considerable amount of memory. For the reason, we recommend using a high memory Linode for such setups.

    This are written for a non-root user. Commands that require elevated privileges is prefixed with sudo . If you're not sudo a familiar with the command, you can check our Users and Groups guide.

    Before you Begin
      1. Ensure that has followed the Getting Started and securing Your Server guides, and the Linode ' s hostname is set.

        To check your hostname run:

        12
        Hostnamehostname-f

        The first command should show your short hostname, and the second should show your fully qualified domain name (FQDN).

      2. Update Your system:

        1
        sudo yum update
    Install MySQL

    MySQL must is installed from the Community repository.

      1. Download and add the repository, then update.

        123 
         wget Http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpmsudo RPM-IVH Mysql-community-release-el7-5.noarch.rpmyum update 
      2. Install MySQL As usual and start the service. During installation, you'll be asked if your want to accept the results from the. rpm file's GPG verification. If no error or mismatch occurs, enter  y .

        12 
         sudo y Um install Mysql-serversudo systemctl start mysqld 

    MySQL would bind to localhost (127.0.0.1) by default. Please reference our MySQL Remote Access Guide for information on connecting to your databases using SSH.

    Allowing unrestricted access to MySQL in a public IP isn't advised but the address it listens on by modifying The bind-address parameter in /etc/my.cnf . If you decide to bind the MySQL to your public IP, you should implement firewall rules that is only allow connections from SPECIF IC IP addresses.

    Harden MySQL Server
      1. Run the mysql_secure_installation script to address several security concerns in a default MySQL installation.

        1
        sudo mysql_secure_installation

    You'll be given the choice to change the MySQL root password, remove anonymous user accounts, disable root logins Outsid E of localhost, and remove test databases. It is recommended so answer to yes these options. You can read more about the script in the the MySQL Reference Manual.

    Using MySQL

    The standard tool for interacting with MySQL are the mysql client which installs with the mysql-server . The MySQL client is used through a terminal.

    Root Login
    1. To log on to MySQL as the root user:

      1
      Mysql-u root-p
    2. When prompted, enter the root password your assigned when the Mysql_secure_installation script is run.

      You'll then being presented with a welcome header and the MySQL prompt as shown below:

      1
      Mysql>
    3. To generate a list of commands for the MySQL prompt, enter \h . You'll then see:

      123456789101112131415161718192021222324252627282930
       List of all MySQL commands:note This all text commands must is first on line and end with '; '? (\?) Synonym for ' help '. Clear (\c) Clear command. Connect (\ r) reconnect to the server. Optional arguments is DB and host. Delimiter (\d) Set statement delimiter. Note:takes the rest of the line as new delimiter. Edit command with $EDITOR. \e. Ego (\g) Send command to MySQL server, display result vertically. Exit (\q) exit MySQL. Same as quit. Go (\g) Send command to MySQL server. Help (\h) Display. Nopager (\ n) Disable Pager, print to stdout. Notee (\ t) Don ' t write into outfile. Pager (\p) Set Pager [To_pager]. Print the query results via PAGER. Print (\p) print current command. Prompt (\ r) Change your MySQL prompt. Quit (\q) quit MySQL. Rehash (\#) Rebuild completion hash. Source (\.) Execute an SQL script file. Takes a file name as an argument. Status (\s) Get status information from the server.System (\!) Execute a system shell command. Tee (\ t) Set outfile [To_outfile]. Append everything into given outfile. Use (\u) use another database. Takes database name as argument. CharSet (\c) Switch to another charset. Might is needed for processing binlog with Multi-Byte charsets. Warnings (\w) Show warnings after every statement. Nowarning (\w) Don ' t show warnings after every statement. For server side help, type ' help Contents ' mysql>
    Create a New MySQL User and Database
    1. The example below, is the name of the testdb database, is the testuser user, and is the password user ' s password.

      123
      Create DATABASE TestDB; Create user ' testuser ' @ ' localhost ' identified by ' password '; Grant all on testdb.* to ' testuser ' identified by ' password ';

      You can shorten this process by creating the user while assigning database permissions:

      12
      Create DATABASE TestDB; Grant all on testdb.* to ' testuser ' identified by ' password ';
    2. Then exit MySQL.

      1
      Exit
    Create a Sample Table
      1. Log back in as  testuser .

        1 
         mysql- U testuser-p 
      2. Create a sample table called  customers. This creates a table with a customer ID field of the Type INT to Integer (auto-incremented for new records, used as the P Rimary key), as well as both fields for storing the customer's name.

        12 
         use Te Stdb;create Table Customers (customer_id INT not NULL auto_increment PRIMARY KEY, first_name text, last_name text); 
      3. Then exit MySQL.

        1 
         exit

    Reset the MySQL Root Password

    If you forget your root for MySQL password, it can be reset.

    1. Stop the current MySQL server instance, then restart it with an option to not ask for a password.

      12
      sudo systemctl stop Mysqldsudo mysqld_safe--skip-grant-tables &
    2. Reconnect to the MySQL server with the MySQL root account.

      1
      Mysql-u Root
    3. Use the following commands to reset root ' s password. Replace with password a strong password.

      1234
      Use Mysql;update user SET Password=password ("PASSWORD") WHERE user= ' root '; flush Privileges;exit
    4. Then restart MySQL.

      1
      sudo systemctl start mysqld
    Tune MySQL

    MySQL Tuner is a Perl script this connects to a running instance of MySQL and provides configuration recommendations based On workload. Ideally, the MySQL instance should has been operating for at least hours before the running. The longer the instance has been running, the better advice MySQL Tuner would give.

      1. Download MySQL Tuner to your home directory.

        1
        wget https://raw.githubusercontent.com/major/MySQLTuner-perl/master/mysqltuner.pl
      2. To run it:

        1
        Perl./mysqltuner.pl

        You'll be asked for the MySQL root user ' s name and password. The output would show the areas of interest:general recommendations and Variables to adjust.

    MySQL Tuner is an excellent starting point to optimize a MySQL server it would was prudent to perform additional resear CH for configurations tailored to the application (s) utilizing MySQL on your Linode.

    More information

    wish to consult the following resources for additional information on this topic. While these is provided in the hope that they would be useful, please note this we cannot vouch for the accuracy or Timeli Ness of externally hosted materials.

      • MySQL 5.6 Reference Manual
      • PHP MySQL Manual
      • Perl DBI examples for dbd::mysql
      • MySQLdb User ' s Guide
      • MySQL Tuner Tutorial

How to Install MySQL on CentOS 7

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.