How to install the database on a Linux system in a virtual machine

1. Check whether there is an older version of linux mysql (have deleted)
Find old mysql: rpm -qa | grep mysql
Uninstall: Uninstall command: rpm -ev {package name} -: rpm -ev mysql-community -common-5.7 .23-1.el7.x86_64
find older versions of mysql related to the installation directory command: find / -name mysql
if it can find the relevant directory using the command: rm -rf {directory name}: delete directory

2, see under linux is installed mariadb database (delete any need, because there is a conflict)
to check whether the installation mariadb: rpm -qa | grep mariadb
delete mariadb: rpm -e --nodeps mariadb-libs -5.5.52-1.el7.x86_64

3. Create mysql storage directory (/ root / software)
create a folder: mkdir / root / software
extract to the current folder, and move the unpacked files to the specified folder and repair the folder name:
unpack: tar -xzvf mysql- 5.7.24-linux-glibc2.12-x86_64.tar.gz
move and change the name: mv mysql-5.7.24-linux- glibc2.12-x86_64 / usr / local / mysql

4, create a home directory (data: ------ storage directory can be omitted)
create a master directory: mkdir / usr / local / mysql / data

5, the main directory permissions process (see if you have users, delete and create a new user)
to view group and user situations: cat / etc / group | grep mysql
view group and user situations: cat / etc / passwd | grep mysql
If there , then delete the original mysql user: userdel -r mysql, deletes the corresponding groups and users and view at times.
Create a mysql group: groupadd mysql
create mysql user: useradd -r -g mysql mysql
modify the directory owner: chown -R mysql: mysql / usr / local / mysql


6, create a profile and related directories (if the path already exists in this case would not have created)
to create the configuration file: vi /etc/my.cnf

[mysqld]
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
port = 3306
socket=/tmp/mysql.sock
pid-file=/tmp/mysqld/mysqld.pid
character-set-server = utf8
log-error=/var/log/mysqld.log

# Modify the configuration file: Note to be to modify the [mysqld] the following template (basedir: mysql installation path, datadir: data storage directory)

Save and exit: wq!

Create a file /tmp/mysql.sock: Setting up user groups and users, authorize
Touch /tmp/mysql.sock
chown MySQL: MySQL /tmp/mysql.sock
chmod 755 /tmp/mysql.sock


Create a file /tmp/mysqld/mysqld.pid

mkdir /tmp/mysqld
chown -R mysql:mysql /tmp/mysqld

touch /tmp/mysqld/mysqld.pid
chmod 755 /tmp/mysqld/mysqld.pid

Create a file /var/log/mysqld.log:

touch /var/log/mysqld.log
chown -R mysql:mysql /var/log
chmod 755 /var/log/mysqld.log

 

7: Install and initialize the database

Enter initialization directory: cd / usr / local / mysql / bin /

Database Initialization: ./ mysqld --initialize --user = mysql --basedir = / usr / local / mysql - datadir = / usr / local / mysql / data

如果报错:(./mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory)

You need to install the command: yum -y install numactl

After initialization is performed in a database: ./ mysqld --initialize --user = mysql --basedir = / usr / local / mysql - datadir = / usr / local / mysql / data

If the error:.. [ERROR] --initialize specified but the data directory has files in it Aborting again empty data directory)


8: Safe boot:

./mysqld_safe --user=mysql &

After enter into the bin directory

View success: ps -ef | grep mysql

Save the default password mysqld.log log, to find a safe place: cat /var/log/mysqld.log|grep password

Which root @ localhost: the default password is behind

Go to the bin directory:

cd /usr/local/mysql/bin/

Login mysql:

./mysql -u root -p

However, if the input related commands, you will be prompted to modify user password (note must be added later;).

show databases;

Password changed to aaa

mysql> set password=password("root");


9: Set up remote access permissions (set in mysql inside)

mysql>grant all privileges on *.* to 'root'@'%' identified by 'root';

Refresh login permissions:

mysql> flush privileges;

Quit quit or exit

mysql> quit;


10: Power service startup settings:

The support-files / mysql.server copy of /etc/init.d/mysql:

Command: cp -a /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql

To see if the success :( named mysql)

cd /etc/init.d/

ll

See if mysql service in the service configuration

chkconfig --list mysql

If not, put mysql registered for the start-up of the service, and then conducting View

chkconfig --add mysql

chkconfig --list mysql

Start or stop

service mysql start

service mysql stop


11: Create a shortcut:
service startup, run directly mysql -u root -p to log in, do not need to enter the corresponding directory.

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


12: occurs when connecting to the database using Navicat (2003)
show that you are not related to the firewall.


solution:

// temporary closure systemctl stop firewalld


// Disable boot

systemctl disable firewalld


Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.


Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.

Guess you like

Origin www.cnblogs.com/huainanhai/p/11110280.html