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

mysql安装步骤

ben0124 2024-04-30
264

1. 上传并解压安装包:mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz

tar -zxvf mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz

2. 检查是否有mysql用户组和用户,没有需要创建

#检查是否存在

[root@liurui-node-5 packages]# groups mysql

groups: mysql: no such user

#创建命令

groupadd mysql

useradd -g mysql mysql

[root@liurui-node-5 packages]# groups mysql

mysql : mysql

 

3. 创建数据目录并赋予权限,例如:

mkdir -p /data/mysql

chown mysql:mysql -R /data/mysql

4. 修改配置文件/ect/my.cnf

[root@liurui-node-5 packages]# cat /etc/my.cnf

[mysqld]

bind-address=0.0.0.0

port=3306

user=mysql

basedir=/usr/local/mysql  

datadir=/data/mysql            

socket=/tmp/mysql.sock

# 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

character_set_server=utf8mb4

 

[mysqld_safe]

log-error=/data/mysql/mysql.err

pid-file=/data/mysql/mysql.pid

explicit_defaults_for_timestamp=true

#

# include all files from the config directory

#

!includedir /etc/my.cnf.d

 

##安装包解压后的路径,将解压后的文件移动到/usr/local/mysql(文件夹名称修改为不带版本号信息)

basedir=/usr/local/mysql  

##上一步中创建的数据目录

datadir=/data/mysql            

##Log-error、pid-file的路径默认都在data目录中,socket的路径默认在/tmp下(.sock文件用于连接本机数据库时不需要ip和port就可以连接),需要指定路径时这些路径必须提前存在,否则初始化或启动失败

5. 初始化

#切换到/usr/local/mysql/bin目录执行./mysqld --initialize命令

[root@liurui-node-5 bin]# pwd

/usr/local/mysql/bin

#执行初始化命令,可以得到临时密码

./mysql --default-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/data/mysql --user=mysql --initialize

6. 启动mysql

#将mysql.server文件复制到/etc/init.d目录

cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql

#启动mysql

service mysql start

7. 修改密码

(1)开启免密码登录,修改/etc/my.cnf文件,在[mysqld]模块下添加skip-grant-tables保存退出

(2)重启服务,使配置生效:service mysql restart

(3)登录 /usr/local/mysql/bin/mysql -u root -p  --不输密码能够登录成功

(4)刷新规则允许外部访问:

   Use mysql  #选择访问mysql数据库

   Update user set host=’%’ where user=’root’ #使root能在任何host访问

   Flush privileges;  #刷新

(5) 修改密码:alter user “root”@”%” identified by ‘111111’;

             Flush privileges;

(6) 退出,把/ect/my.cnf免密删掉,重启服务即可用新密码登录

8. 创建链接,使执行mysql -uroot -p命令即可登录数据库

系统会默认查找/usr/bin下的命令,如果这个命令不再这个目录下,会找不到命令,需要映射一个链接到/usr/bin目录下,相当于建立一个链接文件。创建链接,解决登陆时只能通过安装路径/bin/mysql -uroot -p方式登录:

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

#登录数据库

[root@liurui-node-5 gbase]# mysql -uroot -p111111

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 7

Server version: 5.7.28 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>

 

「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论