只需要一把操作轻松安装mysql

一、安装包直通车 

 https://downloads.mysql.com/archives/community/

二、下载上传

  134  2024-08-21 11:19:08 cp mysql-5.7.44-linux-glibc2.12-x86_64.tar.gz  /usr/local/
  135  2024-08-21 11:19:16 cd /usr/local/
  136  2024-08-21 11:19:16 ls
  137  2024-08-21 11:19:28  tar -zxvf mysql-5.7.44-linux-glibc2.12-x86_64.tar.gz
  139  2024-08-21 11:22:01  mv mysql-5.7.44-linux-glibc2.12-x86_64 mysql-5.7.44
  141  2024-08-21 11:22:12 groupadd mysql
  142  2024-08-21 11:22:13 useradd -r -g mysql mysql
  143  2024-08-21 11:22:33 cd mysql-5.7.44/
  144  2024-08-21 11:22:36 mkdir data
  146  2024-08-21 11:23:13 chown -R mysql.mysql /usr/local/mysql-5.7.44
  148  2024-08-21 11:23:25 cd support-files/
  150  2024-08-21 11:23:37 vim my_default.cnf 具体内容在文末
  153  2024-08-21 11:26:23 cp my_default.cnf /etc/my.cnf
  161  2024-08-21 11:28:23 cd bin/  
  162  2024-08-21 11:28:44 ./mysqld --initialize --user=mysql --basedir=/usr/local/mysql-5.7.44/ --datadir=/usr/local/mysql-5.7.44/data/
执行完后记住密码此处
  177  2024-08-21 11:40:36 cp /usr/local/mysql-5.7.44/support-files/mysql.server /etc/init.d/mysql
  178  2024-08-21 11:40:39 service mysql start
  179  2024-08-21 11:41:10 netstat -ano
  180  2024-08-21 11:41:26 netstat -ano | findstr 3306
  202  2024-08-21 11:49:50 ln -s /usr/local/mysql-5.7.44/bin/mysql /usr/bin
  203  2024-08-21 11:49:52 cd /
  204  2024-08-21 11:49:59 mysql -uroot -p

  其中:my_default.cnf内容如下 vim my_default.cnf

[mysqld]
basedir = /usr/local/mysql-5.7.44/
datadir = /usr/local/mysql-5.7.44/data
port = 3306
socket = /tmp/mysql.sock
character-set-server=utf8
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
[mysqld_safe]
#log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d

三、登录enjoy 

3.1设置密码

修改数据库密码
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';
刷新权限
flush privileges;

 3.2远程登陆

远程登录

select host from user where user='root';

设置谨慎操作

update user set host = '%' where user = 'root';


flush privileges;

四、安装问题

4.1端口占用

[root@VM-20-10-centos bin]# service mysql start
Starting MySQL.Logging to '/usr/local/mysql-5.7.44/data/VM-20-10-centos.err'.
.. ERROR! The server quit without updating PID file (/usr/local/mysql-5.7.44/data/VM-20-10-centos.pid).

[root@VM-20-10-centos bin]# ps -ef | grep mysqld
root     15479     1  0 21:02 ?        00:00:00 /bin/sh /usr/local/mysql-5.7.44//bin/mysqld_safe --datadir=/usr/local/mysql-5.7.44/data --pid-file=/usr/local/mysql-5.7.44/data/VM-20-10-centos.pid
mysql    15659 15479  0 21:02 ?        00:00:00 /usr/local/mysql-5.7.44/bin/mysqld --basedir=/usr/local/mysql-5.7.44/ --datadir=/usr/local/mysql-5.7.44/data --plugin-dir=/usr/local/mysql-5.7.44//lib/plugin --user=mysql --log-error=VM-20-10-centos.err --pid-file=/usr/local/mysql-5.7.44/data/VM-20-10-centos.pid --socket=/tmp/mysql.sock --port=3306
root     31866  3198  0 21:40 pts/0    00:00:00 grep --color=auto mysqld
[root@VM-20-10-centos bin]# pkill -9 mysqld
[root@VM-20-10-centos bin]# service mysql start
Starting MySQL. SUCCESS!

 4.2软连接占用

[root@VM-20-10-centos bin]# ln -s /usr/local/mysql-5.7.44/bin/mysql /usr/bin
ln: failed to create symbolic link ‘/usr/bin/mysql’: File exists

   查看链接内容

ls -l /usr/bin/mysql

   删除链接

sudo rm /usr/bin/mysql

4.3mysqldump找不到

[root@VM-20-10-centos ~]# whereis mysqldump
mysqldump: /usr/local/mysql-5.7.44/bin/mysqldump

方法一 

vim /etc/profile

export MYSQL_HOME=/usr/local/mysql-5.7.44

export PATH=.:${MYSQL_HOME}/bin:$PATH

source /etc/profile

 方法二

查看到地址添加一个软连接即可

ln -s /usr/local/mysql-5.7.44/bin/mysqldump  /usr/bin

最后请记住几个命令吧

systemctl restart mysql

service start mysql

systemctl reload mysql

systemctl status mysql
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值