暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

CentOS7 环境二进制包安装mysql-5.7.40

懿霖 2023-12-25
602

CentOS7 环境二进制包安装mysql-5.7.40

1.目录规划

/u01/mysql/ ├── data │   └── 3306 │   ├── data │   ├── logfile │   ├── pid │   ├── socket │   └── tmp ├── sh └── svr [root@192-168-0-22 mysql]# mkdir -p /u01/mysql/{data/3306/{data,logfile,pid,socket,tmp},svr,sh} [root@192-168-0-22 mysql]# ll total 0 drwxr-xr-x. 3 root root 18 Jun 24 04:35 data drwxr-xr-x. 2 root root 6 Jun 24 04:35 sh drwxr-xr-x. 4 root root 52 Jun 24 04:34 svr

2.解压、建立软连接、并授权目录

【注:onedb-5.7.40-43-linux-x86_64.tar.gz为作者自行使用源码编译的二进制包,修改了版权信息】

[root@192-168-0-22 ~]# cd /u01/mysql/svr/ [root@192-168-0-22 svr]# tar -xzvf onedb-5.7.40-43-linux-x86_64.tar.gz mysql-5.7.40 [root@192-168-0-22 svr]# ln -s mysql-5.7.40 mysql [root@192-168-0-22 svr]# ll total 0 lrwxrwxrwx. 1 mysql mysql 12 Jan 27 04:42 mysql -> mysql-5.7.40 drwxr-xr-x. 12 mysql mysql 188 Jun 24 04:46 mysql-5.7.40 [root@192-168-0-22 svr]# [root@192-168-0-22 svr]# chown -R mysql.mysql /u01/mysql/

3.编辑配置文件:/u01/mysql/data/3306/my3306.cnf

【注:关于MySQL对应配置文件my.cnf 默认搜索顺序可以通过“mysql --help”查看,顺序为:
/etc/my.cnf /etc/mysql/my.cnf /usr/local/mysql/etc/my.cnf ~/.my.cnf】

[root@192-168-0-22 3306]# cat my3306.cnf [mysqld] basedir=/u01/mysql/svr/mysql datadir=/u01/mysql/data/3306/data socket=/u01/mysql/data/3306/socket/mysql.sock pid-file=/u01/mysql/data/3306/pid/mysqld.pid port=3306 log-error=/u01/mysql/data/3306/logfile/mysqld.log [mysql] socket=/u01/mysql/data/3306/socket/mysql.sock [client] socket=/u01/mysql/data/3306/socket/mysql.sock [root@192-168-0-22 3306]#chown -R mysql.mysql my3306.cnf

4.初始化数据库:(建立默认的库和表)

【注:1、初始化时,data目录必须为空,2、将随机生成的登录密码记录下来】

[root@192-168-0-22 bin]# mysqld --defaults-file=/u01/mysql/data/3306/my3306.cnf --initialize --user=mysql [root@192-168-0-22 bin]# [root@192-168-0-22 bin]# tail /u01/mysql/data/3306/logfile/mysqld.log 2023-06-23T21:09:46.607586Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2023-06-23T21:09:47.394319Z 0 [Warning] InnoDB: New log files created, LSN=45790 2023-06-23T21:09:47.466786Z 0 [Warning] InnoDB: Creating foreign key constraint system tables. 2023-06-23T21:09:47.531845Z 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: 48cb4617-120a-11ee-85db-000c29a96888. 2023-06-23T21:09:47.532910Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened. 2023-06-23T21:09:47.661154Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher. 2023-06-23T21:09:47.661174Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher. 2023-06-23T21:09:47.661798Z 0 [Warning] CA certificate ca.pem is self signed. 2023-06-23T21:09:47.696318Z 1 [Note] A temporary password is generated for root@localhost: mo#5iqd3.ikD [root@192-168-0-22 bin]#

5.启动数据库

[root@192-168-0-22 bin]# [root@192-168-0-22 bin]# su - mysql Last login: Sat Jun 24 04:57:48 CST 2023 on pts/0 [mysql@192-168-0-22 ~]$ mysqld --defaults-file=/u01/mysql/data/3306/my3306.cnf & [1] 15528 [mysql@192-168-0-22 ~]$ [mysql@192-168-0-22 ~]$ ps -ef|grep mysql root 15470 9155 0 05:11 pts/0 00:00:00 su - mysql mysql 15471 15470 0 05:11 pts/0 00:00:00 -bash mysql 15528 15471 20 05:11 pts/0 00:00:01 mysqld --defaults-file=/u01/mysql/data/3306/my3306.cnf mysql 15593 15471 0 05:11 pts/0 00:00:00 ps -ef mysql 15594 15471 0 05:11 pts/0 00:00:00 grep --color=auto mysql [mysql@192-168-0-22 ~]$ [mysql@192-168-0-22 ~]$ netstat -nlp|grep mysql (Not all processes could be identified, non-owned process info will not be shown, you would have to be root to see it all.) tcp6 0 0 :::3306 :::* LISTEN 15528/mysqld unix 2 [ ACC ] STREAM LISTENING 52222 15528/mysqld /u01/mysql/data/3306/socket/mysql.sock [mysql@192-168-0-22 ~]$

6.连接数据库:第一次强制修改密码

[mysql@192-168-0-22 ~]$ [mysql@192-168-0-22 ~]$ mysql -uroot -pmo#5iqd3.ikD -S /u01/mysql/data/3306/socket/mysql.sock mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the AbcSQL monitor. Commands end with ; or \g. Your OneDB connection id is 2 Server version: 5.7.40-43 Copyright (c) 2000, 2023 China ABC Cooperation Co., Ltd Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> mysql> status; ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement. mysql> mysql> alter user 'root'@'localhost' identified with mysql_native_password by 'Abc_1234'; Query OK, 0 rows affected (0.00 sec) mysql> create user 'root'@'%' identified with mysql_native_password by 'Abc_1234'; Query OK, 0 rows affected (0.00 sec) mysql> grant all privileges on *.* to 'root'@'%' with grant option; Query OK, 0 rows affected (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) mysql> exit Bye

7.连接数据库:正常使用

[mysql@192-168-0-22 ~]$ mysql -uroot -pGauss_234 -S /u01/mysql/data/3306/socket/mysql.sock mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the OneDB monitor. Commands end with ; or \g. Your OneDB connection id is 3 Server version: 5.7.40-43 Source distribution Copyright (c) 2000, 2023 China Mobile System Integration Co., Ltd Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> mysql> status; -------------- mysql Ver 14.14 Distrib 5.7.40-43, for Linux (x86_64) using 6.2 Connection id: 3 Current database: Current user: root@localhost SSL: Not in use Current pager: stdout Using outfile: '' Using delimiter: ; Server version: 5.7.40-43 Source distribution Protocol version: 10 Connection: Localhost via UNIX socket Server characterset: latin1 Db characterset: latin1 Client characterset: utf8 Conn. characterset: utf8 UNIX socket: /u01/mysql/data/3306/socket/mysql.sock Uptime: 2 min 5 sec Threads: 1 Questions: 12 Slow queries: 0 Opens: 115 Flush tables: 1 Open tables: 33 Queries per second avg: 0.096 -------------- mysql>
最后修改时间:2023-12-25 23:31:09
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论