Install MySQL environment and configuration under Linux

Introduction to mysql

MySQL is a relational database management software. The characteristic of relational databases is to store data in different two-dimensional tables. The most commonly used standardized language for accessing and managing MySQL databases is SQL structured query language.

1. MySQL installation

There are many ways to install mysql, the simplest and most suitable is the binary method installation. Next, we use the mysql binary package to install and deploy mysql

Unzip software

  • tar xf mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz -C /data1/server/
  • cd /data1/server/
  • ln -s mysql-5.6.35-linux-glibc2.5-x86_64 mysql

Create a dedicated user

  • useradd -s /sbin/nologin -M mysql

Initialize the mysql database

  • /data1/server/mysql/scripts/mysql_install_db --basedir=/data1/server/mysql --datadir=/data1/server/mysql/data1/ --user=mysql

Related configuration files

Database configuration file management

  • mv /etc/my.cnf /etc/my.cnf-bak
  • cp /data1/server/mysql/support-files/my-default.cnf /etc/my.cnf

Database startup command configuration (simultaneously copied to the input command)

  • cp /data1/server/mysql/support-files/mysql.server /etc/init.d/mysqld
  • chmod +x /etc/init.d/mysqld

Start file modification

  • sed -i 's#/usr/local/mysql#/data1/server/mysql#g' /data1/server/mysql/bin/mysqld_safe /etc/init.d/mysqld

After the file is modified, enter cat /etc/init.d/mysqld and modify the path to / data1 / server / mysql

Database file permission management

  • chown -R mysql.mysql /data1/server/mysql/

Detailed explanation of sed file content modification commands (simpler than vim command editing content):

Start the database

Check before starting the database

  • netstat -tnulp | grep mysql

Start the database

  • /etc/init.d/mysqld start

Check the database startup status

  • netstat -tnulp|grep mysqld

Configure environment variables

  • vim /etc/profile

# Add this configuration at the end (the role is to add all commands of mysql to all command paths)

  • PATH=/data1/server/mysql/bin:$PATH  

Make the configuration file effective

  • source /etc/profile

At this point, the mysql installation is complete: test whether the installation is successful, directly enter the mysql command

Database command operation

  • show databases; <--- query the default database information

Choose to use a database

  • use mysql; <--- means to choose to use a database, which is equivalent to CD entering a database

View the current database

  • select database (); <--- means to view the current database, similar to the function of pwd command

View the user currently logged in to the database

  • select user (); <--- view the user currently logged in to the database, similar to the whoami command and mysql can also restrict where the specified user can connect to log in to the database

View the directory where you can log in to the mysql database

  • select user, host from mysql.user; --- View the directory where you can log in to the mysql database, and where you can manage the mysql database

Create a database

  • create database database name; ===> can create a database

Via show databases; view

Create a user for the specified database

        The user who created a database:

  • grant all on iwebshop.* to 'iwebshop'@'localhost' identified by '123456'; 
  • grant all on database name. * to 'database login user name' @ 'database login host' identified by 'password'; 

#Create a user wordpress with permissions of all, and set the network segment that allows login, and finally set the password

After creating a user, update the database information flush privileges;

  • mysql> flush privileges;   refresh privileges
  • #flush privileges After creating users, update the database information

    View the user information of the database select user, host from mysql.user;

Delete a database

  • drop database database; ===> can delete a database, through show databases; view

 

 

Published 29 original articles · Like1 · Visits 574

Guess you like

Origin blog.csdn.net/wennie11/article/details/105536900