Install mysql service under Linux

1. Here I will install Mysql in the /usr/local/mysql directory, and it can also be installed in other places;

mkdir /usr/local/mysql

2. Download the installation package from the MySQL official website

This is what I downloaded

3. Unzip and copy

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

4. Create the data directory

mkdir /usr/local/mysql/data

5. Create mysql user group and its users

groupadd mysql
useradd -r -g mysql mysql

If it already exists, it doesn't matter, it doesn't affect the installation

6. Initialize data

[root@localhost mysql] ./bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/
2016-01-20 02:47:35 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
2016-01-20 02:47:45 [WARNING] The bootstrap log isn't empty:
2016-01-20 02:47:45 [WARNING] 2016-01-19T18:47:36.732678Z 0 [Warning] --bootstrap is deprecated. Please consider using --initialize instead
2016-01-19T18:47:36.750527Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 5000)

2016-01-19T18:47:36.750560Z 0 [Warning] Changed limits: table_open_cache: 431 (requested 2000)

7. Copy the configuration file to /etc/my.cnf

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

I don't have my-default.cnf installed, I copied it from somewhere else

8. The MySQL service script is placed in the system service

cp -a ./support-files/mysql.server /etc/init.d/mysqld
Modify my.cnf file
# These are commonly set, remove the # and set as required.
basedir = /usr/local/mysql
datadir = / usr/local/mysql/data
port = 3306
# server_id = .....
socket = /tmp/mysql.sock //Because someone has installed mysql in the test environment before me, so I don't know why this address, I Write /var/lib/mysql.sock to make
character-set-server = utf8
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M

# read_rnd_buffer_size = 2M

9. Create In

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

10. Start the service

service mysqld start

11. Initialize password

mysql5.7 will generate an initialization password in the root .mysql_secret file.

[root@localhost ~]# cat /root/.mysql_secret
# Password set for user 'root@localhost' at 2017-03-16 00:52:34 
ws;fmT7yh0CM

12. Log in and change the password. If the wrong password is always reported here, you can write it in my.cnf

Original: https://blog.csdn.net/lisongjia123/article/details/57418989


After you can log in without a password:


After logging in with the modified password, log in again, and then use alter to modify the password and it can be used normally.


 
 
[root@localhost ~]# mysql -u root -p

alter user root@localhost identified by 'tiger';

flush privileges;

13. Log out and log in again, complete

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+

rows in set (0.11 sec)

原创:https://www.cnblogs.com/xiaotao726/p/6562265.html



Guess you like

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