One: Delete the existing mysql steps
1 Uninstall the old mysql
Which file mysql query has 1.1
[root@zookeeper init.d]# find / -name mysql
/var/lock/subsys/mysql
/var/lib/mysql
/usr/local/soft/mysql
/usr/local/soft/mysql/mysql
/usr/local/soft/mysql/mysql/include/mysql
/usr/local/soft/mysql/mysql/bin/mysql
/usr/local/soft/mysql/mysql/data/mysql
/usr/lib64/mysql
/usr/lib64/perl5/auto/DBD/mysql
/usr/lib64/perl5/DBD/mysql
/usr/share/mysql
/usr/bin/mysql
1.2 and then click Delete
[root @ ZooKeeper init.d] # RM -rf / var / Lock / subsys / MySQL
..... the file and then click Delete
2 delete a profile
2.1 Delete mysql configuration file (my.cnf file)
[root@zookeeper init.d]# rm -rf /etc/my.cnf
2.2 Delete all files in /etc/init.d/ with mysql-related, generally include mysql mysqld file or files.
This document specifies what mysql file, you can check for yourself, then removed, for example, I:
3. Delete the mysql user and group
[root@ali228 ~]# userdel mysql userdel: user 'mysql' does not exis
to here. mysql has been deleted is complete, you can install a new mysql
II: Installation Steps
Ready to work:
Download the installation package in two ways :( Note: do not rush to operate )
Method 1: Download the official website: https://dev.mysql.com/downloads/mysql/5.7.html#downloads
Second way: through wget linux command
1. Go to the mysql installation directory (best create your own)
cd /usr/local/soft/mysql
2. Download the tar.gz package mysql
(I used here is wget way, why? Simple ah, but this requires fast execution speed, otherwise you still honestly downloaded on the physical machine, and then spread it on a virtual machine)
3. Once downloaded, to find their own download package mysql
[root@ali228 mysql] ll /usr/local/soft/mysql
Check your installation package
Then extract
tar -zxvf mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
File after extracting the folder name "mysql-5.7.24-linux-glibc2.12-x86_64" modify the mysql (you would expect, yes, then there are two mysql folder)
mv mysql-5.7.24-linux-glibc2.12-x86_64 mysql
4. Add users and user groups mysql mysql, and added to the user group mysql
[root@ali228 mysql]# groupadd mysql [root@ali228 mysql]# useradd -r -g mysql mysql
Note: useradd -r parameter indicates the system user mysql user, can not be used to log system.
useradd -g parameter represents the user to add mysql mysql user group.
5. Check the installation libaio
rpm -qa | grep libaio
If not, then execute:
yum search libaio
6. my.cnf configuration file
we /etc/my.cnf
We will look to copy the contents of the file inside
[mysql]
# mysql client set the default character set
default-Character-SET = UTF8
Socket = / tmp / mysql.sock
[mysqld]
# Skip-name-Resolve
# 3306 port disposed
Port = 3306
Socket = / tmp / mysql.sock
# set the mysql real installation directory (see ourselves is where)
basedir = / usr / local / Soft / mysql / mysql
# set the mysql database storage directory data (see ourselves is where)
datadir = / usr / local / Soft / MySQL / MySQL / Data
# maximum number of connections
max_connections = 200 is
# character set the server uses the default is 8 bits for encoding latin1 character Diao
character-set-server = utf8
default storage to be used when # create a new table Ti primer
default = INNODB-Storage-Engine
# =. 1 lower_case_table_name
the max_allowed_packet = 16M
7. Create a data folder (datadir in my.cnf is specified folder)
[root@baidu64 mysql]# pwd
/usr/local/soft/mysql/mysql
[root@baidu64 mysql]# mkdir data
8. mysql user belongs to the group directory and mysql
chown -R mysql:mysql ./
9. Initialization Initialization mysqld generated password (note file address)
[root@baidu64 mysql]# ./bin/mysqld --initialize --user=mysql --basedir=/usr/local/soft/mysql/mysql --datadir=/usr/local/soft/mysql/mysql/data
In this case, the output is:
2018-10-24T04:25:13.673365Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2018-10-24T04:25:15.808961Z 0 [Warning] InnoDB: New log files created, LSN=45790 2018-10-24T04:25:16.105505Z 0 [Warning] InnoDB: Creating foreign key constraint system tables. 2018-10-24T04:25:16.184776Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: cec94f21-d744-11e8-a0b5-fa163ed8e403. 2018-10-24T04:25:16.188372Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened. 2018-10-24T04:25:16.189074Z 1 [Note] A temporary password is generated for root@localhost: i;lknXwO;5,s [root@baidu64 mysql]#
The "root @ localhost:" content behind the record, this is the first landing mysql password required (if not written down, you have to reinstall it again oh)
10.mysql Configuration
10.1 Setting the boot:
10.1.1 Copy mysql.server script to the resource directory and given execute permissions:
Before setting we first understand something :( hurry, then do not read)
Start mysql, we can:
./support-files/mysql.server
this to start, but each had to go in response to the output file or folder, inevitably some trouble, then what are the alternatives?
We look at /etc/rc.d/init.d this file: This directory is that some of the script, the script usually start when a number of services to linux rpm package installation set. In a lot of the fashion system installed rpm package, there is there is a lot of corresponding script.
Execute these scripts can be used to start, stop, restart these services.
So when we put our mysql startup script on "/etc/rc.d/init.d/mysqld" file, you can easily start the mysql
[root@baidu64 mysql]# cp ./support-files/mysql.server /etc/rc.d/init.d/mysql.server
[root@baidu64 mysql]# chmod +x /etc/rc.d/init.d/mysql.server
“chmod +x /etc/rc.d/init.d/mysql.server”
设置完这个后,就可以通过:mysqld快捷启动了: service mysql.server start
10.1.2:将 mysqld 服务加入到系统服务并检测是否生效:
[root@baidu64 mysql]# chkconfig --add mysql.server
[root@baidu64 mysql]# chkconfig --list mysql.server
可以启动mysql了:
service mysql.server start
11.配置环境变量
11.1 在 /etc/profile配置文件中,添加如下内容:
首先: vi /etc/profile
然后再文件中添加内容:(不会vi操作的可以百度一下,这是基本操作)
#mysql环境变量
PATH=$PATH:/usr/local/soft/mysql/mysql/bin export PATH
11.2 执行命令,使etc/profile生效
source /etc/profile
11.3 校验是否成功:
[root@baidu64 mysql]# echo $PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/home/env/jdk/jdk8/jdk1.8.0_171/bin:/root/bin:/home/env/jdk/jdk8/jdk1.8.0_171/bin:/usr/local/env/mysql/mysql/bin
12. 初次登录 修改访问密码(第一次的密码就是 上边我让你记得密码,可以回去看下第9步)
[root@baidu64 mysql]# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 5 Server version: 5.7.18 Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql>
修改登录密码:(为 '123456')
mysql> SET PASSWORD = PASSWORD('123456'); Query OK, 0 rows affected, 1 warning (0.00 sec) mysql> use mysql; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql> update user set authentication_string=PASSWORD('123456') where User='root'; Query OK, 0 rows affected, 1 warning (0.00 sec) Rows matched: 1 Changed: 0 Warnings: 1 mysql>
13.允许远程访问
mysql> grant all privileges on *.* to root@"%" identified by "password" with grant option; Query OK, 0 rows affected, 1 warning (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) mysql>
14.使用navicate远程连接报错
14.1关闭mysql服务
[root@baidu64 mysql]# service mysql.server stop
Redirecting to /bin/systemctl stop mysql.service
如果提示‘mysql unrecognized service’,则执行:
cp ./support-files/mysql.server /etc/rc.d/init.d/mysql.server
然后执行:
chmod +x /etc/rc.d/init.d/mysql.server
在执行:service mysql.server start
15. 修改/etc/my.cnf修改为无密码登录
在my.cnf配置文件添加如下内容:
# mysql无密码登录
skip-grant-tables
16.重启mysql服务
[root@baidu64 mysql]# service mysql.server restart
Redirecting to /bin/systemctl restart mysql.service
17.无密码登录mysql
[root@baidu64 mysql]# mysql -u root Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3 Server version: 5.7.18 MySQL Community Server (GPL) Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql>
18.再次修改mysql密码:
mysql> use mysql; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql> update mysql.user set authentication_string=password('123456') where user='root' ; Query OK, 1 row affected, 1 warning (0.00 sec) Rows matched: 2 Changed: 1 Warnings: 1 mysql>
19.
然后将my.cnf无密码登录配置去掉(就是上面刚加的那句话)
20.退出mysql,并重启:
mysql> quit Bye [root@baidu64 mysql]# service mysql restart Redirecting to /bin/systemctl restart mysql.service [root@baidu64 mysql]#
21.重新连接
问题一:socket file /tmp/mysql.sock exists. Is another MySQL daemon already running with the same unix socket?
执行:etc/init.d/mysql.server restart
报错: Stopping mysqld: [ OK ] Socket file /tmp/mysql.sock exists. Is another MySQL daemon already running with the same unix socket? Starting mysqld:
原因多个Mysql进程使用了同一个socket。
此时,只需要将这个socket文件删除即可这个文件删除掉也没事,因为:
Mysql有两种连接方式:MySQL客户可以两种不同的方式连接mysqld服务器:Unix套接字,它通过在文件系统中的一个文件(缺省“/tmp/mysqld.sock”)进行连接;或TCP/IP,它通过一个端口号连接。
(1)TCP/IP
(2)socket 作用: 发起本地连接
mysql.sock是随每一次 mysql server启动生成的,因此mysql服务连接不上的根本原因还是配置文件设置出问题了。
MySQL下mysql.sock丢失丢失的原因一般是因为配置文件不一致的原因,mysqld 错误启动,mysqld_safe 会清除一次mysql.sock 。
(这个文件在哪?可以去my.cnf中查找)??
然后去删除
rm -rf 文件路径
问题二:
ervice mysqld start 重启数据库总是会出现如下提示:
MySQL Daemon failed to start.
Starting mysqld: [FAILED]
如果直接输入 mysql -root -p登陆会出现[mysql]ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)的错误提示。总之MySql服务器端总是无法启动。网上的提供很多解决方法也没有效果。最后通过如下方法解决:
运行以下命令:
rm /var/lock/subsys/mysqld killall mysqld
然后再执行:
service mysql.server start