Linux installation mySQL database

Linux install mySQL database:

1. Installation path

mkdir /usr/local/mysql

Installation package:

wget http://dev.MySQL.com/get/Downloads/MySQL-5.7/mysql-5.7.11-Linux-glibc2.5-x86_64.tar.gz

If you use the intranet, you can receive the download package http://dev.MySQL.com/get/Downloads/MySQL-5.7/mysql-5.7.11-Linux-glibc2.5-x86_64.tar.gz###

Unzip to the target path

tar -xvf mysql-5.7.11-Linux-glibc2.5-x86_64.tar.gz
mv mysql-5.7.11-Linux-glibc2.5-x86_64/* /usr/local/mysql/

The directory is /usr/local/mysql/* (including bin, etc.) ###

2. Create the data directory

mkdir /usr/local/mysql/data

Create mysql user group and its users

groupadd mysql
useradd -r -g mysql mysql

3. Initialize data

./bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/

Copy the configuration file to /etc/my.cnf

cp -a ./support-files/my-default.cnf /etc/my.cnf (选择y)

The MySQL service script is placed in the system service

cp -a ./support-files/mysql.server /etc/init.d/mysqld

Modify the my.cnf file

** basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
port = 3306
bind-address = 0.0.0.0
# server_id = .....
socket = /tmp/mysql.sock
character-set-server = utf8 **

Create In

    `ln -s /usr/local/mysql/  /usr/bin/`
    

4. Start the service

service mysqld start

Initialize password:

    `cat /root/.mysql_secret`

Login and change password

Possible problems bash: mysql: command not found

    解决:
    **cd /usr/local/bin**
    **ln -fs /MYSQLPATH/bin/mysql mysql** MYSQLPATH=user/local/mysql 即MySQL路径

General databases are only available for users, so you need to set up ordinary users

Add a new user: first log in to the root user

    `create user 'test'@'%' identified by '123456'; ` %为任何外网Ip都可以连接  若为localhost 只能本地连接

Assign database permissions to users

    `grant all privileges on `testdb`.* to 'test'@'%' identified by '123456';`

Submit permission changes

    `flush privileges;`

Also possible problems:

MySQL connection error Can't connect to MySQL server on

Solution:

The server is CentOS7, and the MySQL service is added to the firewall

    `sudo firewall-cmd --zone=public --permanent --add-service=mysql`

restart firewall

    `sudo systemctl restart firewalld`

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324999451&siteId=291194637