CentOSCentOS7.0 mysql and uninstallation

mysql installation:

Using the command

yum list mysql-server When installing mysql, I found that there is no mysql package. At this time, we need to download a

Download package

wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm

Download is complete, install the mysql-community-release-el7-5.noarch.rpm package

sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm

Install mysql

sudo yum install mysql-server

Wait for the installation to complete….

Then select Y

After the installation is complete, mysql does not have a password and needs to be reset.

mysql -u root

ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ (2)

Solution:

1. The mysql service is not running normally:

Since the mysql socket file is created when the mysqld service starts, if the mysqld service does not start normally, the socket file will naturally not be created, and of course the socket file will not be found. To determine whether the mysql service is started, we can use the following command:

Copy code

# 1. Is the port open?
[[email protected] ~]# lsof -i:3306
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
mysqld 12207 mysql 14u IPv4 52350 0t0 TCP *:mysql (LISTEN)
 
# 2. Is the mysqld service running?
[[email protected] ~]# service mysqld status
mysqld (pid 4717) is running...

Copy code

2. The socket file path is incompletely set in the configuration file:

This is generally caused by us modifying the mysql configuration “/etc/my.cnf”. For example, we modified the “socket” parameter under the “[mysql]” option in the configuration file without specifying the “socket” parameter of the “[client]” and “[mysql]” options, causing mysql to use the default socket file location. Looking for a socket file, causing this error to occur as the socket file is not found.

1. The mysql service is not running normally:

If the service is not started, we can run “service mysqld start” to start the service. If the service cannot be started, check the mysql service log to find the cause and solve it before starting it.

Copy code

[[email protected] ~]# service mysqld start
Starting mysqld: [OK]
[[email protected] ~]# lsof -i:3306
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
mysqld 14109 mysql 10u IPv4 247183583 0t0 TCP *:mysql (LISTEN)
[[email protected] ~]# service mysqld status
mysqld (pid 14109) is running...

Copy code

2. Improve the mysql configuration file:

If it is confirmed that the mysql service is running normally and the error in the article title is prompted, then it is a problem with the “/etc/my.cnf” configuration file. The solution is to modify the “/etc/my.cnf” configuration file, add the “[client]” option and the “[mysql]” option in the configuration file, and use the “socket” parameter value under these two options, and ” The “socket” parameter value under the “[mysqld]” option points to the same socket file path. as follows:

Copy code

[mysqld]
datadir=/storage/db/mysql
socket=/storage/db/mysql/mysql.sock
...omit n lines...
 
[client]
default-character-set=utf8
socket=/storage/db/mysql/mysql.sock
 
[mysql]
default-character-set=utf8
socket=/storage/db/mysql/mysql.sock

Copy code

Original address: http://www.aiezu.com/db/mysql_cant_connect_through_socket.html

If the problem still cannot be solved, try the following:

Check below things to fix the issue

Check the permission of mysql data dir using below command

# ls -ld /var/lib/mysql/

Check the permission of databases inside mysql data dir using below command

# ls -lh /var/lib/mysql/

Check the listening network tcp ports using below command

# netstat -ntlp

Check the mysql log files for any error using below command.

# cat /var/log/mysql/mysqld.log

Try to start mysql using below command

# mysqld_safe --defaults-file=/etc/my.cf

change Password:

# mysql -uroot -p
Enter password: [Enter the original password] (If you set the root password for the first time after installing mysql, just press Enter)
mysql>use mysql;
mysql> update user set password=password("123456") where user='root';
mysql> flush privileges;
mysql> exit;

How to configure mysql to allow remote connections

By default, mysql only allows local login. If you want to enable remote connections, you need to modify the /etc/mysql/my.conf file.

1. Modify /etc/mysql/my.conf
Find the line bind-address = 127.0.0.1
Just change it to bind-address = 0.0.0.0

2. Grant permissions to users who need to log in remotely

1. Create a new user to remotely connect to the mysql database

mysql>use mysql;

mysql>create user luffy IDENTIFIED by '123456'; //identified by will encrypt the plain text password and store it as a hash value<br>
mysql>grant select,delete,update,insert on *.* to 'luffy'@'%' identified by '123456' ;
mysql>flush privileges;

Allow computers with any IP address (% means allow any IP address) to use the luffy account and password (123456) to access this mysql server.

2. Support root users to allow remote connection to mysql database

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

3. View system users

PS. If you still can’t connect remotely, you can refer to:

https://jingyan.baidu.com/article/380abd0a3aef431d90192c33.html

mysql installation 2

1. Download the mysql installation package mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz

2. First cd /usr/local: and then decompress tar -zxvf mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz

After decompression, you can change the decompressed file name to mysql for the convenience of subsequent operations:

mv mysql-5.7.23-linux-glibc2.12-x86_64 mysql

3. Then go to the support-files directory and copy my.cnf to /etc/my.cnf (automatically read when mysqld starts) cp my-default.cnf /etc/my.cnf

The latest version no longer has the file my-default.cnf.

my.cnf

[client]
loose_default-character-set = utf8<br>socket = /usr/local/mysql/data/mysql.sock<br>
[mysqld]
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
port=3306
#server_id = 1
socket = /usr/local/mysql/data/mysql.sock
expire_logs_days = 7
innodb_file_per_table
innodb_buffer_pool_size = 2G
innodb_thread_concurrency = 24
innodb_flush_log_at_trx_commit = 1
innodb_log_buffer_size = 32M
innodb_log_file_size = 256M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
wait_timeout = 60
interactive_timeout = 7200
skip-name-resolve
character-set-server=utf8
back_log = 50
max_connections = 3000
max_connect_errors = 32
max_allowed_packet = 32M
binlog_cache_size = 8M
max_heap_table_size = 512M
tmp_table_size = 64M
key_buffer_size = 16M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
bulk_insert_buffer_size = 64M
sort_buffer_size = 4M
join_buffer_size = 2M
thread_cache_size = 64
thread_stack = 192K
query_cache_type = 1
query_cache_size = 256M
query_cache_limit = 2M
ft_min_word_len = 2
default_storage_engine = INNODB
#default_table_type = INNODB
transaction_isolation = REPEATABLE-READ
lower_case_table_names = 1
#log_slow_queries
slow_query_log
long_query_time = 2
log-short-format
myisam_sort_buffer_size = 128M
myisam_max_sort_file_size = 10G
myisam_repair_threads = 1
[mysqldump]
quick
max_allowed_packet = 32M
routines
single-transaction
hex-blob
skip-comments
complete-insert
skip-disable-keys
skip-add-locks
skip-lock-tables
[isamchk]
key_buffer = 512M
sort_buffer_size = 512M
read_buffer = 8M
write_buffer = 8M
[myisamchk]
key_buffer = 512M
sort_buffer_size = 512M
read_buffer = 8M
write_buffer = 8M
[mysqlhotcopy]
interactive-timeout
# 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
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

4. Copy mysql.server to the /etc/init.d/ directory [The purpose is to achieve the automatic execution effect at boot]

Execute command: cp mysql.server /etc/init.d/mysql (mysql is the service name)

5. Modify the /etc/init.d/mysql parameter vi /etc/init.d/mysql to give 2 directory locations basedir=/usr/local/mysqldatadir=/usr/local/mysql/data

6. For security and convenience, create a dedicated user for operating the database

1), groupadd mysql #Create a mysql group

2), useradd -r -g mysql mysql #Create a mysql user and put the user in the mysql group

3), passwd mysql #Set a password for the mysql user

4). Change the owner of the directory /usr/local/mysql chown -R mysql:mysql /usr/local/mysql/

Initialize mysql database

First go to the bin directory of mysql

1. Initialization./mysqld –initialize –user=mysql –basedir=/usr/local/mysql –datadir=/usr/local/mysql/data

A data directory is generated, which means that the database has been initialized successfully and the root user of mysql has generated a temporary password: xxxxx (it is best to record this temporary password first)

The following problem encountered is caused by operation 1, which was not executed

Fatal error: Can’t open and lock privilege tables: Table ‘mysql.user’ doesn’t exist

2. Encrypt the database./mysql_ssl_rsa_setup –datadir=/usr/local/mysql/data

3. Start mysql (in order to prevent the process from being stuck, you can add & after the command to start mysql to indicate that the process is running in the background)./mysqld_safe –user=mysql &;

4. Check ps -ef|grep mysql

If the above processes are found, it means the startup is successful.

Step 5: Enter the client

1. Log in ./mysql -uroot -p and press Enter and enter the previous temporary password 2. Change the password set password=password(‘new password’);

mysql: command not found

Solution: # ln -s /usr/local/mysql/bin/mysql /usr/bin

mysql uninstall:

1. Use the following command to check the current installation of mysql and find out whether mysql has been installed before

rpm -qa|grep -i mysql

You can see it as shown in the figure below:

2. Stop the mysql service and delete the previously installed mysql

Delete command: rpm -e –nodeps package name

rpm -ev MySQL-client-5.5.25a-1.rhel5
rpm -ev MySQL-server-5.5.25a-1.rhel5

If you are prompted with a dependency package error, try using the following command

rpm -ev MySQL-client-5.5.25a-1.rhel5 --nodeps

If an error message is displayed: error: %preun(xxxxxx) scriptlet failed, exit status 1

Then try the following command:

rpm -e --noscripts MySQL-client-5.5.25a-1.rhel5

3. Find the directory of the previous version of mysql and delete the files and libraries of the old version of mysql

find / -name mysql

The search results are as follows:

find / -name mysql
 
/var/lib/mysql
/var/lib/mysql/mysql
/usr/lib64/mysql

Delete the corresponding mysql directory

rm -rf /var/lib/mysql
rm -rf /var/lib/mysql
rm -rf /usr/lib64/mysql

The specific steps are as shown in the figure: Find the directory and delete it

Note: /etc/my.cnf will not be deleted after uninstallation and needs to be deleted manually.

rm -rf /etc/my.cnf

4. Check again whether the machine has mysql installed

rpm -qa|grep -i mysql

Reference address: https://www.cnblogs.com/wolf-sun/p/5655439.html

Reference address: https://www.cnblogs.com/nicknailo/articles/8563456.html

Reference address: https://www.aliyun.com/jiaocheng/133867.html?spm=5176.100033.1.15.22996b04YjkV5D