Mysql version 5.5. 56 (binary package installation) custom installation path step record
- 2021-08-17 01:18:00
- OfStack
Installation path:/application/mysql-5. 5.56
1. Prepare
mysql dependency
libaio
yum install -y libaio
The user mysql is created and the mysql is executed as the user
useradd -s /bin/false -M mysql
Download and unzip the mysql2 binary package
cd /tools
wget https://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.56-linux-glibc2.5-x86_64.tar.gz
tar -zxf mysql-5.5.56-linux-glibc2.5-x86_64.tar.gz -C /application/
Switch to the/application directory, shorten the name of mysql folder, and make a soft link to mysql directory
cd /application/
mv mysql-5.5.56-linux-glibc2.5-x86_64/ mysql-5.5.56
ln -s mysql-5.5.56/ mysql
Recursively set the group to which the mysql directory belongs and the user to which it belongs
chown -R mysql:mysql mysql-5.5.56/
2. mysql in-directory operations
cd mysql
Initialize the database
One data directory will be generated in the mysql directory, which is the directory for storing the database
./scripts/mysql_install_db --basedir=/application/mysql --datadir=/application/mysql/data/ --user=mysql
Change Owning Users and Groups
chown -R root .
chown -R mysql data
Except that the user of data directory under mysql directory is unchanged, the user of all other files is changed to root
Copy configuration file
cp support-files/my-medium.cnf /etc/my.cnf
Copy the configuration file of mysql to my. cnf under the directory/etc
Modify the configuration file
sed -i 28i'log-error=/application/mysql/data/mysqld.error' /etc/my.cnf
Insert 1 line in the configuration file to log configuration errors
useradd -s /bin/false -M mysql
0
Copy startup program
cp support-files/mysql.server /etc/init.d/mysql
Copy the startup program for mysql to the/etc/init. d/directory to start the program
Edit the startup file and configure the startup directory
Method 1:
The idea is to assign values to variables provided by configuration files. More troublesome.
sed -i ':a;N;$!ba;s/basedir=\ndatadir=/basedir=\/application\/mysql\ndatadir=\/application\/mysql\/data/g' /etc/init.d/mysql
sed -i ':a;N;$!ba;s/mysqld_pid_file_path=\n/mysqld_pid_file_path=\/application\/mysql\/data\/mysqld.pid\n/g' /etc/init.d/mysql
Equivalent to putting lines 45 and 46
useradd -s /bin/false -M mysql
3
Replace with
useradd -s /bin/false -M mysql
4
Method 2 (recommended):
The idea is to replace the default address of the script (/usr/local/mysql) directly with a custom path (/application/mysql) without assigning a value to the variable
useradd -s /bin/false -M mysql
5
Here, mysql can start normally after installation
3. Late end
Command to create a soft link
mysql command creation is soft-linked to the directory of environment variables, so that users can find the corresponding commands in the variables
useradd -s /bin/false -M mysql
6
Setting and modifying passwords
Set password for the first time:
mysqladmin -u'' password ''
Examples:
mysqladmin -u'root' password 'PassWord'
Change the password later:
useradd -s /bin/false -M mysql
9
Examples:
mysqladmin -u'root' -p'PassWord' password 'NewPassWord'
Login to mysql
$ mysql -u'root' -p'PassWord'
Welcome to the MySQL monitor. Commands end with ; or \g.
...
mysql> # Successfully logged in to mysql Console
$ mysql -uroot -pPassWord
Welcome to the MySQL monitor. Commands end with ; or \g.
...
mysql> # Successfully logged in to mysql Console
$ mysql -u'root' -p
Enter password: # Enter the user's password here
Welcome to the MySQL monitor. Commands end with ; or \g.
...
mysql > # Login to mysql console successfully
$ mysql -uroot -p
Enter password: # Enter the user's password here
Welcome to the MySQL monitor. Commands end with ; or \g.
...
mysql > # Login to mysql console successfully
Type quit or Ctrl + d to exit the mysql environment
mysql> quit
Bye
[root@www mysql]#
or
mysql> ^DBye
[root@www mysql]#
4. Common commands
Enter mysql
mysql -u'root' -p'PassWord'
mysql -uroot -pPassWord
mysql -u'root' -p
mysql -uroot -p
Start mysql
service mysql start
Stop mysql
service mysql stop
Restart mysql
service mysql restart