目标
过程
# 修改主机名[root@localhost ~]# hostnamectl set-hostname server[root@localhost ~]# su -上一次登录:二 9月 14 08:47:17 CST 2021tty1 上[root@server ~]## 上传安装包并解压[root@server ~]# lsanaconda-ks.cfg mysql-5.6.47-linux-glibc2.12-x86_64.tar.gz[root@server ~]#[root@server ~]# tar -zxvf mysql-5.6.47-linux-glibc2.12-x86_64.tar.gz# 移动到指定目录[root@server ~]# mv mysql-5.6.47-linux-glibc2.12-x86_64 /usr/local/mysql/# 创建MySQL启动用户,不可登录[root@server ~]# useradd -s /sbin/nologin mysql# 创建存放数据目录[root@server ~]# mkdir -p /data/mysql# 更改所属组,所属用户权限[root@server ~]# chown -R mysql:mysql /data/mysql/[root@server ~]# ls -la /data/mysql/总用量 0drwxr-xr-x. 2 mysql mysql 6 9月 14 08:38 .drwxr-xr-x. 3 root root 19 9月 14 08:38 ..[root@server ~]# cd /usr/local/mysql/# 安装依赖[root@localhost mysql]# yum install -y perl-Module-Install[root@server mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql/[root@server mysql]# echo $?0[root@localhost mysql]# cp support-files/my-default.cnf /etc/my.cnfcp:是否覆盖"/etc/my.cnf"? y[root@localhost mysql]# vim /etc/my.cnfbasedir = /usr/local/mysqldatadir = /data/mysqlport = 3306server_id = 29socket = /tmp/mysql.sock[root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysqld[root@localhost mysql]# chmod 777 /etc/init.d/mysqld[root@localhost mysql]# vim /etc/init.d/mysqldbasedir=/usr/local/mysqldatadir=/data/mysql[root@localhost mysql]# chkconfig --add mysqld[root@localhost mysql]# chkconfig mysqld on[root@localhost mysql]# service mysqld startStarting MySQL.Logging to '/data/mysql/localhost.localdomain.err'.SUCCESS![root@localhost mysql]# netstat -ntlpActive Internet connections (only servers)Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program nametcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 941/sshdtcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1189/mastertcp6 0 0 :::22 :::* LISTEN 941/sshdtcp6 0 0 ::1:25 :::* LISTEN 1189/mastertcp6 0 0 :::3306 :::* LISTEN 2210/mysqld# 配置环境变量[root@server mysql]# vim /etc/profile# 最后一行添加export PATH=$PATH:/usr/local/mysql/bin[root@server mysql]# source /etc/profile[root@server mysql]# mysqladmin -uroot password '123456'
如果出错先设置密码
# 在知道或者是没有密码的情况下配置密码# 二进制免编译安装的MySQL是没有密码的,首先设置一个密码[root@lnmp ~]# mysqladmin -uroot password '123456'# 在不知道密码的情况下重置密码[root@lnmp ~]# vim /etc/my.cnf# 在mysqld下添加skip-grant这一行[mysqld]skip-grant # 忽略用户认证# 重启服务生效[root@lnmp ~]# service mysqld restartShutting down MySQL.. SUCCESS!Starting MySQL. SUCCESS!# 免密登录[root@server ~]# mysql -urootWelcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 1Server version: 5.6.47 MySQL Community Server (GPL)Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> mysql> show databases;+--------------------+| Database |+--------------------+| information_schema || mysql || performance_schema || test |+--------------------+4 rows in set (0.00 sec)mysql> use mysql;Reading table information for completion of table and column namesYou can turn off this feature to get a quicker startup with -ADatabase changedmysql># 更新密码mysql> update user set password=password('123456') where user='root';Query OK, 4 rows affected (0.00 sec)Rows matched: 4 Changed: 4 Warnings: 0mysql> Ctrl-C -- exit!Aborted[root@server ~]# vim /etc/my.cnf# 去掉skip-grant字段# 重启生效[root@lnmp ~]# service mysqld restartShutting down MySQL.. SUCCESS!Starting MySQL. SUCCESS!# 使用新密码登录[root@server ~]# mysql -uroot -p123456Warning: Using a password on the command line interface can be insecure.Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 1Server version: 5.6.47 MySQL Community Server (GPL)Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql>
到这里二进制免编译MySQL安装配置完成。
