mysql数据库部署

1.检查环境并关闭selinux
[root@localhost ~]# getenforce
Enforcing
[root@localhost ~]# setenforce 0
[root@localhost ~]# getenforce
Permissive
[root@localhost ~]# cat /etc/selinux/config
SELINUX=disabled

2.官网【mysql.com】下载部署,上传,解压
[root@localhost ~]# md5sum mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz
[root@localhost ~]# tar -zxvf mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz
[root@localhost ~]# mkdir -p /usr/local/app/
[root@localhost app]# mv mysql-5.7.26-linux-glibc2.12-x86_64 /usr/local/app/
[root@localhost app]# rpm -ivh libaio-0.3.109-13.el7.x86_64.rpm #安装依赖
[root@localhost app]# mv mysql-5.7.20-linux-glibc2.12-x86_64 mysql

3.创建mysql用户和数据目录并修改权限
[root@localhost app]# useradd mysql
[root@localhost app]# mkdir /data/mysql -p
[root@localhost app]# chown -R mysql.mysql /usr/local/app/*
[root@localhost app]# chown -R mysql.mysql /data/* #注意/data下面是否有其他目录或文件

4.数据库初始化
[root@localhost bin]# /usr/local/app/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/app/mysql --datadir=/data/mysql
2024-10-14T08:20:48.422961Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2024-10-14T08:20:48.652291Z 0 [Warning] InnoDB: New log files created, LSN=45790
2024-10-14T08:20:48.699275Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2024-10-14T08:20:48.776503Z 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: 37d22bcb-8a05-11ef-b56c-000c292ea57c.
2024-10-14T08:20:48.777090Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2024-10-14T08:20:48.777591Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.

5.添加环境变量(最好在第三步之前添加,可以直接用mysqld初始化)
vim /etc/profile
export PATH=/usr/local/app/mysql/bin/:$PATH
[root@localhost mysql]# source /etc/profile

6.书写默认配置文件
[root@localhost etc]# cat my.cnf
[mysqld]
user=mysql
basedir=/usr/local/app/mysql
datadir=/data/mysql
server_id=6
port=3306
socket=/tmp/mysql.sock
[mysql]
socket=/tmp/mysql.sock

7.直接启动mysql
[root@localhost support-files]# pwd
/usr/local/app/mysql/support-files
[root@localhost support-files]# /usr/local/app/mysql/support-files/mysql.server start
[root@localhost support-files]# /usr/local/app/mysql/support-files/mysql.server status
SUCCESS! MySQL running (9428)

8.配置systemctl管理mysql

[root@localhost system]# cat /etc/systemd/system/mysql.service 
[Unit]
Description=MySQL Server
Documentation=man:mysqld
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=/usr/local/app/mysql/bin/mysqld --defaults-file=/etc/my.cnf
LimitNOFILE = 5000

[root@localhost bin]# systemctl  daemon-reload
[root@localhost system]# systemctl start mysql.service
[root@localhost system]# systemctl status mysql.service
[root@localhost system]# ps aux | grep mysql
mysql      9574  0.1  9.1 1117776 171104 ?      Ssl  17:33   0:00 /usr/local/app/mysql/bin/mysqld --defaults-file=/etc/my.cnf
root       9632  0.0  0.0 112708   980 pts/1    R+   17:36   0:00 grep --color=auto mysql
[root@localhost system]# 
[root@localhost system]# 
[root@localhost system]# netstat -anlp | grep mysql
tcp6       0      0 :::3306                 :::*                    LISTEN      9574/mysqld         
unix  2      [ ACC ]     STREAM     LISTENING     49697    9574/mysqld          /tmp/mysql.sock
unix  3      [ ]         STREAM     CONNECTED     49671    9574/mysqld          

9.测试进入数据库

[root@localhost data]# 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.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> 

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

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> show tables;
+---------------------------+
| Tables_in_mysql           |
+---------------------------+
| columns_priv              |
| db                        |
| engine_cost               |
| event                     |
| func                      |
| general_log               |
| gtid_executed             |
| help_category             |
| help_keyword              |
| help_relation             |
| help_topic                |
| innodb_index_stats        |
| innodb_table_stats        |
| ndb_binlog_index          |
| plugin                    |
| proc                      |
| procs_priv                |
| proxies_priv              |
| server_cost               |
| servers                   |
| slave_master_info         |
| slave_relay_log_info      |
| slave_worker_info         |
| slow_log                  |
| tables_priv               |
| time_zone                 |
| time_zone_leap_second     |
| time_zone_name            |
| time_zone_transition      |
| time_zone_transition_type |
| user                      |
+---------------------------+
31 rows in set (0.00 sec)

mysql> 

10.进程占用
2024-10-14T08:54:03.995393Z 0 [Note] InnoDB: Check that you do not already have another mysqld process using the same InnoDB data or log files.
2024-10-14T08:54:05.001701Z 0 [ERROR] InnoDB: Unable to lock ./ibdata1 error: 11
2024-10-14T08:54:05.001729Z 0 [Note] InnoDB: Check that you do not already have another mysqld process using the same InnoDB data or log files.
2024-10-14T08:54:06.012634Z 0 [ERROR] InnoDB: Unable to lock ./ibdata1 error: 11
2024-10-14T08:54:06.012654Z 0 [Note] InnoDB: Check that you do not already have another mysqld process using the same InnoDB data or log files.

[root@localhost support-files]# ps -aux | grep mysql
mysql 8988 0.0 9.1 1117480 171400 pts/1 Sl+ 16:57 0:00 /usr/local/app/mysql/bin/mysqld --defaults-file=/etc/my.cnf
root 9056 0.0 0.0 112708 980 pts/0 R+ 17:06 0:00 grep --color=auto mysql
[root@localhost support-files]#
[root@localhost support-files]#
[root@localhost support-files]# kill -9 8988

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 216,324评论 6 498
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 92,356评论 3 392
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 162,328评论 0 353
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,147评论 1 292
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,160评论 6 388
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,115评论 1 296
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,025评论 3 417
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 38,867评论 0 274
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,307评论 1 310
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,528评论 2 332
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,688评论 1 348
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,409评论 5 343
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,001评论 3 325
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,657评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,811评论 1 268
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 47,685评论 2 368
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,573评论 2 353