赞
踩
- mkdir /mytools
- cd /mytools
wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.30-linux-glibc2.12-x86_64.tar.gz
tar -zxvf mysql-5.7.30-linux-glibc2.12-x86_64.tar.gz
ln -s /mytools/mysql-5.7.30-linux-glibc2.12-x86_64 /mytools/mysql
rpm -e --nodeps mariadb-libs
- vim /etc/my.cnf
-
- // [mysqld] 这是代表对服务端生效的参数
- // [mysql] 这是代表对客户端的生效的参数
-
- [mysqld]
- basedir=/mytools/mysql/
- datadir=/mytools/mysql/data
- socket=/tmp/mysql.sock
- server_id=1
- port=3306
- log_error=/mytools/mysql/data/mysql_err.log
-
- [mysql]
- socket=/tmp/mysql.sock
- 1.检查mysql的所需的依赖环境
- yum install libaio-devel -y
-
- 2.创建mysql数据文件夹,用于初始化数据,且进行权限控制
- mkdir -p /mytools/mysql/data/
- chown -R mysql.mysql /mytools/mysql/ #修改mysql所有的内容,更改属主,属组为mysql用户
-
- 3.初始化mysql数据库
- /mytools/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/mytools/mysql/ --datadir=/mytools/mysql/data/
使用systemctl命令管理mysql数据库
- 编写mysql启动的脚本,定义一个mysqld.service
- touch /etc/systemd/system/mysqld.service #写入如下的内容
-
- [Unit]
- Description=MySQL server by ymh
- 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=/mytools/mysql/bin/mysqld --defaults-file=/etc/my.cnf
- LimitNOFILE=5000
- 1.由于我们配置了mysqld.service脚本,直接用命令启动用
- systemctl start mysqld.service
- #启动完了之后,检查数据库状态,检查为active状态,mysql就正常启动了
-
- [root@iZt4n9649a5hnayu7zbf5rZ system]# systemctl status mysqld
- ● mysqld.service - LSB: start and stop MySQL
- Loaded: loaded (/etc/rc.d/init.d/mysqld; disabled; vendor preset: disabled)
- Active: active (running) since Fri 2024-04-19 02:31:58 CST; 2 days ago
- Docs: man:systemd-sysv-generator(8)
- Process: 930 ExecStart=/etc/rc.d/init.d/mysqld start (code=exited, status=0/SUCCESS)
- Tasks: 24
- Memory: 155.6M
- CGroup: /system.slice/mysqld.service
- ├─ 971 /bin/sh /www/server/mysql/bin/mysqld_safe --datadir=/www/server/data --pid-file=/www/server/data/iZt4n9649a5hnayu7zbf5rZ.pid
- └─1728 /www/server/mysql/bin/mysqld --basedir=/www/server/mysql --datadir=/www/server/data --plugin-dir=/www/server/mysql/lib/plugin --user=m...
-
- Apr 19 02:31:56 iZt4n9649a5hnayu7zbf5rZ systemd[1]: Starting LSB: start and stop MySQL...
- Apr 19 02:31:58 iZt4n9649a5hnayu7zbf5rZ mysqld[930]: Starting MySQL..[ OK ]
- Apr 19 02:31:58 iZt4n9649a5hnayu7zbf5rZ systemd[1]: Started LSB: start and stop MySQL.
-
- 2.检查进程
- ps -ef|grep mysqld
- 3.检查端口
- netstat -tunlp|grep 3306
如果systemctl start mysqld.service启动失败,就使用需要重新初始化数据库
- ll /mytools/mysql/data/
- rm -rf /mytools/mysql/data/*
- /mytools/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/mytools/mysql/ --datadir=/mytools/mysql/data/
- systemctl start mysqld
- systemctl status mysqld
这个mysql是c/s架构模式的,就好比登录qq一样
先启动mysqld服务端,然后用mysql客户端命令登录即可
- 1.如果你电脑之前装过其他的数据库,你可以用yum直接卸载,不会影响到你安装的二进制mysql数据库
- yum remove mysql -y
-
- 2.退出会话,重新登录
-
- 3.配置我们安装的二进制mysgl PATH环境变量
- /mytools/mysql/bin #这是我们安装的二进制mysql命令目录
-
- 当前的PATH变量
- [root@web02 bin]#echo SPATH
- /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/mytools/nginx/sbin:/root/bin
- vim /etc/profile.d/nginx.sh #写入如下新的PATH变量
- export PATH="$PATH:/mytools/mysql/bin"
- echo $PATH
- cd /bin
- mv mysql mysql5.7
- which mysql
- #登录数据库的命令
- [root@iZt4n9649a5hnayu7zbf5rZ bin]# mysql -uroot -p
- Enter password: (这里不需要输入密码,直接回车就能登入mysql)
- Welcome to the MySQL monitor. Commands end with ; or \g.
- Your MySQL connection id is 5
- Server version: 5.7.30 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 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>
mysqladmin -u root password 'ymh' #使用mysqladmint命令,修改root密码为ymh
修改密码后再次想要登录数据库
- [root@iZt4n9649a5hnayu7zbf5rZ -]mysql -uroot -p
- Enter password:
- ERROR 1045 (28000):Access denied for user 'root'@'localhost'(using password:NO)
- 如果你不输入密码,或者输入错误,就会有如上的提示
正确的输入root密码ymh才能登入mysql
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。