mysql5.7安装手册

1、解压压缩包

在/usr/local目录下解压压缩包并改名
[root@oracle local]# tar -zxvf /home/mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz
[root@oracle local]# mv mysql-5.7.22-linux-glibc2.12-x86_64/ mysql/

2、创建用户及组

groupadd mysql

useradd -r -g mysql mysql

chown -R mysql mysql/

chgrp -R mysql mysql/

[root@oracle bin]# vi ~/.bash_profile

export PATH=/usr/local/mysql/bin:$PATH

[root@oraclebin]# source ~/.bash_profile

3、创建配置文件

vi /etc/my.cnf,添加以下内容

[client]
port = 3306
socket = /tmp/mysql.sock

[mysqld]
character_set_server=utf8
init_connect='SET NAMES utf8'
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
socket=/tmp/mysql.sock
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
#不区分大小写
lower_case_table_names = 1

sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

max_connections=5000

default-time_zone = '+8:00'

4、初始化数据库

[root@oracle mysql]# ./bin/mysqld --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/

5、启动数据库

这里第一次启动的时候如果出现以下报错:
Starting MySQL.2019-04-22T08:01:33.448968Z mysqld_safe error: log-error set to ‘/var/log/mariadb/mariadb.log’, however file don’t exists. Create writable for user ‘mysql’.
ERROR! The server quit without updating PID file (/var/run/mysqld/mysqld.pid).

解决方法:
手动创建相关目录及文件,赋予对应权限,然后再启动数据库
[root@oracle support-files]# ./mysql.server start
Starting MySQL. SUCCESS!

6、连接数据库

[root@oracle bin]# ./mysql  -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.22 MySQL Community Server (GPL)

Copyright (c) 2000, 2018, 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> 
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 `Host`='%', `User`='root', `Select_priv`='Y', `Insert_priv`='Y', `Update_priv`='Y', `Delete_priv`='Y', `Create_priv`='Y', `Drop_priv`='Y', `Reload_priv`='Y', `Shutdown_priv`='Y', `Process_priv`='Y', `File_priv`='Y', `Grant_priv`='Y', `References_priv`='Y', `Index_priv`='Y', `Alter_priv`='Y', `Show_db_priv`='Y', `Super_priv`='Y', `Create_tmp_table_priv`='Y', `Lock_tables_priv`='Y', `Execute_priv`='Y', `Repl_slave_priv`='Y', `Repl_client_priv`='Y', `Create_view_priv`='Y', `Show_view_priv`='Y', `Create_routine_priv`='Y', `Alter_routine_priv`='Y', `Create_user_priv`='Y', `Event_priv`='Y', `Trigger_priv`='Y', `Create_tablespace_priv`='Y', `ssl_type`='', `ssl_cipher`='', `x509_issuer`='', `x509_subject`='', `max_questions`='0', `max_updates`='0', `max_connections`='0', `max_user_connections`='0', `plugin`='mysql_native_password', `authentication_string`='*6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9', `password_expired`='N', `password_last_changed`='2017-11-20 12:41:07', `password_lifetime`=NULL, `account_locked`='N' WHERE  (`User`='root');
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql>  flush privileges;
Query OK, 0 rows affected (0.00 sec)

附录:

1、重置root密码方法:

1、打开配置文件/etc/my.cnf,在mysqld下添加一行skip-grant-tables,如下:

[mysqld]
#...
skip-grant-tables
#...
这样我们就可以免密登录MySQL了。

然后保存并退出。

2、重启MySQL

这两个命令21:

$ sudo systemctl restart mysqld
$ sudo service mysqld restart
3、终端输入 mysql 直接登录MySQL数据库:

$ mysql
成功进入mysql

切换到MySQL系统库mysql:

mysql> use mysql;
5、重置root密码

需要注意的是,在MySQL5.7之后,已经没有password这个字段了,

password字段改成了authentication_string。

修改密码我们要修改这个字段的值。

update user set authentication_string=password('新密码') where user='root';
这样,我们就已经修改密码成功了。

(mysql8:ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '新密码';)

5、修改 /etc/my.cnf 文件,将之前添加的skip-grant-tables 这句话注释掉。

不然我们仍然还是免密的方式登录Mysql。

6、再次重启MySQL就大功告成了。

2、报错:

Starting MySQL... ERROR! The server quit without updating PID file (/var/run/mysqld/mysqld.pid).

解决方法参考:https://yq.aliyun.com/articles/492001

3、报错:

ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executin

解决方法参考:https://blog.csdn.net/Brighter_Xiao/article/details/51556532

4、报错:

Host is not allowed to connect to this MySQL server

解决方法参考:https://blog.csdn.net/EI__Nino/article/details/25069391

发布了155 篇原创文章 · 获赞 88 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/weixin_39540651/article/details/105204378