二进制部署mysql
1,创建目录
mkdir -p /app/
#将mysql二进制软件上传至此目录
2,解压软件包并改名为mysql
tar xf mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz
mv mysql-5.7.26-linux-glibc2.12-x86_64 mysql
[root@mister_f ~]# ll /app/mysql/
total 52
drwxr-xr-x 2 root root 4096 May 8 16:24 bin
-rw-r--r-- 1 7161 31415 17987 Apr 13 2019 COPYING
drwxr-xr-x 2 root root 4096 May 8 16:24 docs
drwxr-xr-x 3 root root 4096 May 8 16:24 include
drwxr-xr-x 5 root root 4096 May 8 16:24 lib
drwxr-xr-x 4 root root 4096 May 8 16:24 man
-rw-r--r-- 1 7161 31415 2478 Apr 13 2019 README
drwxr-xr-x 28 root root 4096 May 8 16:24 share
drwxr-xr-x 2 root root 4096 May 8 16:24 support-files
3,修改环境变量
vim /etc/profile
source /etc/profile
4,创建mysql用户和创建相关目录并修改权限
useradd mysql
mkdir /data/mysql -p
chown -R mysql.mysql /app/*
chown -R mysql.mysql /data/*
5,初始化数据库
mysqld --initialize-insecure --user=mysql --basedir=/app/mysql --datadir=/data/mysql
6,生成mysql配置文件
vim /etc/my.cnf
[mysqld]
user=mysql
basedir=/app/mysql
datadir=/data/mysql
server_id=6
port=3306
socket=/tmp/mysql.sock
[mysql]
socket=/tmp/mysql.sock
prompt=3306 [\\d]>
7,使用systemd管理mysql
vim /etc/systemd/system/mysqld.service
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
ExecStart=/app/mysql/bin/mysqld --defaults-file=/etc/my.cnf
LimitNOFILE = 5000
8,启动数据库
systemctl start mysqld
[root@mister_f ~]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.26 MySQL Community Server (GPL)
Copyright (c) 2000, 2019, 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;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
mysql>
9,设置用户密码
[root@mister_f ~]# mysqladmin -uroot -p password 123
10,分析数据库无法启动思路
without updating PID 类似错误
查看日志:
/data/mysql/data/主机名.err
[ERROR] 上下文
可能情况:
/etc/my.cnf 路径不对等
/tmp/mysql.sock文件修改过 或 删除过
数据目录权限不是mysql
参数改错
11,忘记本地管理员用户密码怎么样修改
两个核心参数
--skip-grant-tables #跳过授权表,没有用户名和密码的验证
--skip-networking #跳过远程登录
一般使用这两个参数有两种方式
1,添加到my.cnf的配置文件里
2,使用mysqld_safe临时方式
停止数据库
systemctl stop mysqld
启动数据库到维护模式
mysqld_safe --skip-grant-tables --skip-networking &
#启动后数据库就么有密码了,但是只能在本地连接不能远程连接
mysql> select user,host,authentication_string from mysql.user;
+---------------+-----------+-------------------------------------------+
| user | host | authentication_string |
+---------------+-----------+-------------------------------------------+
| root | localhost | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| mysql.session | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
| mysql.sys | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
+---------------+-----------+-------------------------------------------+
3 rows in set (0.00 sec)
#mysql5.7是使用的authentication_string来存储密码的
登录数据库修改密码
mysql> grant all on *.* to root@'localhost' identified by '123';
ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
#由于关闭了授权的功能,所以要手工的刷新一下;
mysql> flush privileges;
Query OK, 0 rows affected (0.02 sec)
mysql> grant all on *.* to root@'localhost' identified by '123';
Query OK, 0 rows affected, 1 warning (0.00 sec)
或者使用alter语句
mysql> alter user root@'localhost' identified by '1234';
Query OK, 0 rows affected (0.00 sec)
正常关闭重启数据库恢复正常
[root@mister_f ~]# systemctl restart mysqld
[root@mister_f ~]# mysql -p123
mysql: [Warning] 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 3
Server version: 5.7.26-log MySQL Community Server (GPL)
Copyright (c) 2000, 2019, 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>
网友评论