centOS 7 安装 mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz


#卸载系统自带的Mariadb
[root@localhost local]# rpm -qa|grep mariadb
mariadb-libs-5.5.52-1.el7.x86_64
[root@localhost local]# rpm -e --nodeps mariadb-libs-5.5.52-1.el7.x86_64

#删除etc目录下的my.cnf文件
[root@localhost local]# rm /etc/my.cnf
rm: 无法删除"/etc/my.cnf": 没有那个文件或目录

#检查mysql是否存在
[root@localhost local]# rpm -qa | grep mysql
[root@localhost local]# 

#检查mysql组和用户是否存在,如无创建
[root@localhost local]# cat /etc/group | grep mysql
[root@localhost local]# cat /etc/passwd | grep mysql

#创建mysql用户组
[root@localhost local]# groupadd mysql
#创建一个用户名为mysql的用户并加入mysql用户组
[root@localhost local]# useradd -g mysql mysql

#制定password 为**************
[root@localhost local]# passwd mysql
更改用户 mysql 的密码 。
新的 密码:
重新输入新的 密码:
passwd:所有的身份验证令牌已经成功更新。

解压到指定文件夹下
tar -vxzf mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz
mv mysql-5.7.21-linux-glibc2.12-x86_64/ /usr/local/mysql/

#更改所属的组和用户
[root@localhost local]# chown -R mysql mysql/
[root@localhost local]# chgrp -R mysql mysql/
#在mysql文件夹下创建  数据库数据存储目录  data
[root@localhost local]# cd mysql/
[root@localhost mysql]# mkdir data
[root@localhost mysql]# chown -R mysql:mysql data

#在etc下新建配置文件my.cnf,并在该文件内添加以下配置
[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8 
[mysqld]
skip-name-resolve
#设置3306端口
port = 3306 
# 设置mysql的安装目录
basedir=/usr/local/mysql
# 设置mysql数据库的数据的存放目录
datadir=/usr/local/mysql/data
# 允许最大连接数
max_connections=200
# 服务端使用的字符集默认为8比特编码的latin1字符集
character-set-server=utf8
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB 
lower_case_table_names=1
max_allowed_packet=16M

#安装和初始化
[root@localhost mysql]# bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/

2018-03-07 20:15:37 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
2018-03-07 20:15:41 [WARNING] The bootstrap log isn't empty:
2018-03-07 20:15:41 [WARNING] 2018-03-07T12:15:38.240438Z 0 [Warning] --bootstrap is deprecated. Please consider using --initialize instead
2018-03-07T12:15:38.281730Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 5000)
2018-03-07T12:15:38.281756Z 0 [Warning] Changed limits: table_open_cache: 407 (requested 2000)

[root@localhost mysql]# cp ./support-files/mysql.server /etc/init.d/mysqld
#将脚本文件设置成可执行文件
[root@localhost mysql]# chown 777 /etc/my.cnf
[root@localhost mysql]# chmod a+x /etc/init.d/mysqld

[root@localhost mysql]# /etc/init.d/mysqld restart
 ERROR! MySQL server PID file could not be found!
Starting MySQL.Logging to '/usr/local/mysql/data/localhost.localdomain.err'.
. SUCCESS! 
[root@localhost mysql]# killall mysqld
[root@localhost mysql]# /etc/init.d/mysqld start
Starting MySQL. SUCCESS! 
[root@localhost mysql]# /etc/init.d/mysqld restart
Shutting down MySQL.. SUCCESS! 
Starting MySQL. SUCCESS! 
#设置开机启动
[root@localhost mysql]# chkconfig --level 35 mysqld on
[root@localhost mysql]# chkconfig --list mysqld
注意:该输出结果只显示 SysV 服务,并不包含原生 systemd 服务。SysV 配置数据可能被原生 systemd 配置覆盖。 
      如果您想列出 systemd 服务,请执行 'systemctl list-unit-files'。
      欲查看对特定 target 启用的服务请执行
      'systemctl list-dependencies [target]'。

mysqld             0:关    1:关    2:开    3:开    4:开    5:开    6:关

[root@localhost mysql]# chmod +x /etc/rc.d/init.d/mysqld
[root@localhost mysql]# chkconfig --add mysqld
[root@localhost mysql]# chkconfig --list mysqld
[root@localhost mysql]# service mysqld status
 SUCCESS! MySQL running (6272)
#编辑  vi /etc/profile
export PATH=$PATH:/usr/local/mysql/bin
[root@localhost mysql]# source /etc/profile
#获得初始密码
[root@localhost bin]# cat /root/.mysql_secret 
# Password set for user 'root@localhost' at 2018-03-07 20:15:37 
hgfs1Z1uMw2=

#修改密码
[root@localhost bin]# mysql -uroot -p

[root@localhost init.d]# mysql -u root -p
Enter password: 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
#先关闭mysql
[root@localhost init.d]# ./mysqld stop
Shutting down MySQL.. SUCCESS! 
#使用安全模式登陆,跳过密码验证
[root@localhost init.d]# mysqld_safe --user=mysql --skip-grant-tables --skip-networking&
[1] 7059
[root@localhost init.d]# 2018-03-07T12:50:12.826995Z mysqld_safe Logging to '/usr/local/mysql/data/localhost.localdomain.err'.
2018-03-07T12:50:12.861526Z mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data
[root@localhost init.d]# mysql -uroot  mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.21 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> update user set authentication_string = password('**************') where user = 'root' and Host = 'localhost'
    -> ;
Query OK, 1 row affected, 1 warning (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 1

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

mysql> exit
Bye
[root@localhost init.d]# ls
functions  mysqld  netconsole  network  README
[root@localhost init.d]# ./mysqld 
Usage: mysqld  {start|stop|restart|reload|force-reload|status}  [ MySQL server options ]
[root@localhost init.d]# ./mysqld restart
Shutting down MySQL..2018-03-07T12:54:40.379190Z mysqld_safe mysqld from pid file /usr/local/mysql/data/localhost.localdomain.pid ended
 SUCCESS! 
Starting MySQL. SUCCESS! 
[1]+  完成                  mysqld_safe --user=mysql --skip-grant-tables --skip-networking
[root@localhost init.d]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.21

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> show databases
    -> ;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> set password = password ('**************');
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> show databases
    -> ;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

mysql> exit;
Bye
[root@localhost init.d]# ps -ef|grep mysql
root       7407      1  0 20:54 pts/0    00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/data --pid-file=/usr/local/mysql/data/localhost.localdomain.pid
mysql      7608   7407  0 20:54 pts/0    00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=localhost.localdomain.err --pid-file=/usr/local/mysql/data/localhost.localdomain.pid --port=3306
root       7660   5149  0 20:57 pts/0    00:00:00 grep --color=auto mysql
[root@localhost init.d]# ls
functions  mysqld  netconsole  network  README
[root@localhost init.d]# ./mysqld stop
Shutting down MySQL.. SUCCESS! 
[root@localhost init.d]# ps -ef|grep mysql
root       7696   5149  0 20:57 pts/0    00:00:00 grep --color=auto mysql
[root@localhost init.d]# reboot
PolicyKit daemon disconnected from the bus.
We are no longer a registered authentication agent.
Connection closing...Socket close.

Connection closed by foreign host.


#添加远程访问权限
[root@localhost ~]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.21 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> 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 host='%' where user='root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> select host,user from user;
+-----------+---------------+
| host      | user          |
+-----------+---------------+
| %         | root          |
| localhost | mysql.session |
| localhost | mysql.sys     |
+-----------+---------------+
3 rows in set (0.00 sec)
#这里 @‘%’ 表示在任何主机都可以登录
mysql> create user 'xxx'@'%' identified by '123';
Query OK, 0 rows affected (0.00 sec)
#重启mysql
[root@localhost init.d]# ./mysqld restart
Shutting down MySQL.. SUCCESS! 
Starting MySQL. SUCCESS! 
#为了在任何目录下可以登录mysql
[root@localhost init.d]# ln -s /usr/local/mysql/bin/mysql   /usr/bin/mysql







安装过程中可能会报libaio缺失,所以提前安装:yum install libaio 1、在官网上下载mysql-5.7.22-linux,我下载的是mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz,https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.22-linux-glibc2.12-x86_64.tar.gzcentos7/64位。 2、解压tar -zxvf mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz 3、移动目录mv mysql-5.7.22-linux-glibc2.12-x86_64 /usr/local/mysql/mysql-5.7.22 4、创建用户组和用户 groupadd mysql useradd -r -g mysql -s /bin/false mysql chown -R mysql:mysql mysql 5安装mysql bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql/mysql-5.7.22/ --datadir=/usr/local/mysql/mysql-5.7.22/data --lc_messages_dir=/usr/local/mysql/mysql-5.7.22/share --lc_messages=en_US 注意重点记录最后生成的登录密码 6、修改配置 bin/mysql_ssl_rsa_setup --datadir=/usr/local/mysql/mysql-5.7.22/data vi /etc/my.cnf cat /etc/my.cnf 修改结果: [mysqld] basedir=/usr/local/mysql/mysql-5.7.22 datadir=/usr/local/mysql/mysql-5.7.22/data/ 7、配置环境变量 vi ~/.bash_profile 将mysql的bin目录配置到环境变量中 PATH=$PATH:$HOME/bin:/usr/local/mysql/mysql-5.7.22/bin export PATH 8、修改密码 mysql -uroot -p set password=password("新密码"); 9、配置远程访问 use mysql update user set host='%' where user='root'; GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '......' WITH GRANT OPTION;(或者是:grant all privileges on *.* to root@'%' identified by "你的新密码";) FLUSH PRIVILEGES; 10、设置开机自启 cd /usr/local/mysql/mysql-5.7.22/support-files cp mysql.server /etc/init.d/mysql chmod +x /etc/init.d/mysql chkconfig --add mysql chkconfig --list mysql 到此为止,mysql安装完成,并且可以远程访问了 如果远程访问失败,请查看错误原因,比如防火墙未开启相应端口 ———————————————— 版权声明:本文为CSDN博主「xiaoniuxqq」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。 原文链接:https://blog.csdn.net/u011649691/article/details/80512647
### 回答1: MySQL 5.7安装配置教程Linux) 1. 下载MySQL 5.7安装包 从MySQL官网下载MySQL 5.7安装包,选择适合你Linux系统的版本。 2. 安装MySQL 5.7 使用以下命令安装MySQL 5.7: sudo dpkg -i mysql-server_5.7.21-1ubuntu16.04_amd64.deb 3. 配置MySQL 5.7 安装完成后,使用以下命令启动MySQL服务: sudo systemctl start mysql 使用以下命令设置MySQL服务开机自启: sudo systemctl enable mysql 使用以下命令检查MySQL服务状态: sudo systemctl status mysql 4. 设置MySQL 5.7管理员密码 使用以下命令设置MySQL管理员密码: sudo mysql_secure_installation 按照提示输入新密码,然后按照提示回答其他问题。 5. 登录MySQL 5.7 使用以下命令登录MySQL 5.7mysql -u root -p 输入管理员密码,即可登录MySQL 5.7。 6. 配置MySQL 5.7远程访问 默认情况下,MySQL 5.7只允许本地访问。如果需要远程访问MySQL 5.7,需要进行以下配置: 编辑MySQL配置文件: sudo vi /etc/mysql/mysql.conf.d/mysqld.cnf 找到以下行: bind-address = 127...1 将其改为: bind-address = ... 保存并退出。 重新启动MySQL服务: sudo systemctl restart mysql 现在,你可以使用其他计算机上的MySQL客户端连接到MySQL 5.7服务器。 以上就是MySQL 5.7安装配置教程Linux)的全部内容。 ### 回答2MySQL是一个开源的关系型数据库管理系统,是最流行的RDBMS之一。MySQL提供多用户、多线程的SQL数据库服务器,最新版本为MySQL 8.0,在我们日常的开发中使用较多的版本为MySQL 5.7。本文将介绍如何在Linux系统上安装和配置MySQL 5.7。 1. 下载MySQL 5.7 可以从MySQL官网(https://dev.mysql.com/downloads/mysql/5.7.html)下载MySQL 5.7的压缩包,也可以使用命令行下载,命令如下: wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz 2. 解压压缩包 使用以下命令解压压缩包: tar zxvf mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz 3. 安装MySQL 将解压缩后的文件夹放在适当的位置,例如/opt/目录下: sudo mv mysql-5.7.34-linux-glibc2.12-x86_64 /opt/ 进入mysql-5.7.34-linux-glibc2.12-x86_64目录: cd /opt/mysql-5.7.34-linux-glibc2.12-x86_64/ 将该目录下的所有文件拷贝到/usr/local/mysql/目录下: sudo cp -r * /usr/local/mysql/ 进入/usr/local/mysql/目录: cd /usr/local/mysql/ 4. 创建MySQL用户和组 创建mysql用户组: sudo groupadd mysql 创建mysql用户: sudo useradd -r -g mysql -s /bin/false mysql 5. 授权 将所有文件的拥有者设置为mysql用户: sudo chown -R mysql:mysql /usr/local/mysql/ 6. 初始化MySQL 使用以下命令进行初始化: sudo bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data 初始化的时候,会随机生成一个密码。密码会被记录在error.log文件中,例如: 2021-11-03T01:21:19.313799Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: y^s9_p)? 7. 启动MySQL 使用以下命令启动MySQL: sudo service mysql start 使用以下命令停止MySQL: sudo service mysql stop 8. 登录MySQL 使用以下命令登录MySQLmysql -u root -p 输入上一步中生成的密码,即可成功登录MySQL。 以上是MySQL 5.7安装和配置教程,如果你的Linux系统是CentOS7,则可以使用yum进行安装安装完成后,你可以通过MySQL客户端连接和管理该数据库。 ### 回答3: MySQL是目前世界上最流行的开源数据库管理系统之一,各种开发、运营任务中都少不了MySQL的使用。本文将介绍一下在Linux环境下如何安装 MySQL5.7。 一、安装MySQL 1.使用yum安装 在终端中输入一下命令: sudo yum install mysql57-server mysql57 2. 下载安装包 你可以去官方网站https://dev.mysql.com/downloads/mysql/5.7.html下载MySQL 5.7安装包。 下载成功之后,执行以下命令进行安装: sudo rpm -ivh mysql57-community-release-el7-10.noarch.rpm sudo yum install mysql-server 二、配置MySQL 1.启动MySQL 在终端中输入以下命令: sudo systemctl start mysqld.service 2.设置MySQL开机启动 在终端中输入以下命令: sudo systemctl enable mysqld.service 3.修改MySQL密码 在终端中输入以下命令: sudo mysql_secure_installation 根据提示进行修改密码即可。 三、使用MySQL 1.尝试登录MySQL 在终端输入以下命令: mysql -u root -p 输入密码,进入MySQL。 输入exit退出MySQL2.创建数据库和表 输入以下命令: create database database_name; use database_name; create table table_name (column1_name type constraint, column2_name type constraint,...); 例如: create database test; use test; create table students (name varchar(20), age int, address varchar(50)); 3.插入数据 在终端中输入以下命令: insert into table_name value (value1, value2,...); 例如: insert into students value ('Tom', 20, 'Beijing'); 4.查询数据 输入以下命令: select * from table_name; 例如: select * from students; 5.修改数据 在终端中输入以下命令: update table_name set column_name = new_value where condition; 例如: update students set name = 'Jerry' where age = 20; 6.删除数据 在终端中输入以下命令: delete from table_name where condition; 例如: delete from students where age = 20; 到这里我们已经完成了MySQL安装和基本操作的使用。MySQL是一个非常强大的数据库管理系统,在实际的开发运营过程中我们还需要根据实际需要掌握更多的知识和技巧。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值