MySQL安装命令

MySQL安装命令,第1张

MySql安装

yum -y install libaio

wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz

cd /usr/local/soft/mysql/src

mkdir ../5.7.24_3306 &&tar -xzvf mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz -C ../5.7.24_3306 --strip-components 1

mkdir -p /usr/local/soft/mysql/5.7.24_3306/{run,data,logs,bin_log,sock,cert}

groupadd mysql &&useradd -r -g mysql -s /bin/false mysql

cd /usr/local/soft/mysql/5.7.24_3306/bin &&./mysqld --initialize

--explicit_defaults_for_timestamp

--user=mysql

--basedir=/usr/local/soft/mysql/5.7.24_3306

--datadir=/usr/local/soft/mysql/5.7.24_3306/data

--lc_messages_dir=/usr/local/soft/mysql/5.7.24_3306/share

--lc_messages=en_US

2018-12-01T09:56:45.934627Z 0 [Warning] InnoDB: New log files created, LSN=45790

2018-12-01T09:56:46.056837Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.

2018-12-01T09:56:46.127141Z 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: 69d028f9-f54f-11e8-9c4a-00163e08e793.

2018-12-01T09:56:46.130249Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.

2018-12-01T09:56:46.131377Z 1 [Note] A temporary password is generated for root@localhost: sDdPx3>.,oBi

cd /usr/local/soft/mysql/5.7.24_3306/bin &&./mysql_ssl_rsa_setup --datadir=/usr/local/soft/mysql/5.7.24_3306/cert

修改证书权限为644

cd /usr/local/soft/mysql/5.7.24_3306/bin &&./mysql -uroot -S /usr/local/soft/mysql/5.7.24_3306/sock/mysql.sock

use mysql

update user set host = '%', authentication_string = password('123456') where user = 'root'

select host,user,authentication_string from user

flush privileges

grant all privileges on . to 'root'@'%'

flush privileges

cat >/etc/systemd/system/3306.service <<EOF

[Unit]

Description=MySQL 3306

Documentation= http://dev.mysql.com/doc/refman/en/using-systemd.html

After=network.target remote-fs.target nss-lookup.target

[Service]

Type=forking

PIDFile=/usr/local/soft/mysql/5.7.24_3306/run/mysql.pid

ExecStart=/usr/local/soft/mysql/5.7.24_3306/support-files/mysql.server start

ExecReload=/usr/local/soft/mysql/5.7.24_3306/support-files/mysql.server restart

ExecStop=/usr/local/soft/mysql/5.7.24_3306/support-files/mysql.server stop

PrivateTmp=true

[Install]

WantedBy=multi-user.target

EOF

systemctl enable 3306.service

1、

cd /usr/local/soft/mysql/5.7.24.3306/bin &&./mysqld_safe --skip-grant-tables &

cd /usr/local/soft/mysql/5.7.24.3306/bin &&./mysqld_safe --skip-grant-tables --skip-networking &

2、

./mysql -uroot -p -S /usr/local/soft/mysql/5.7.24.3306/sock/mysql.sock

3、

use mysql

update mysql.user set authentication_string=password('123456') where user='root'

flush privileges

mkdir -p /usr/local/soft/mysql/back/5.7.23_3306 &&cp -Rf /usr/local/soft/mysql/5.7.23_3306/* /usr/local/soft/mysql/back/5.7.23_3306

mkdir -p /usr/local/soft/mysql/back/5.7.24_3306 &&cp -Rf /usr/local/soft/mysql/5.7.24_3306/* /usr/local/soft/mysql/back/5.7.24_3306

CREATE USER 'sdyc'@'%' IDENTIFIED BY '123456'

GRANT SELECT, INSERT, UPDATE, DELETE, EXECUTE ON sd_data.* TO 'sdyc'@'%'

GRANT SELECT, INSERT, UPDATE, DELETE, EXECUTE ON card_data.* TO 'sdyc'@'%'

SHOW GRANTS FOR sdyc

CREATE USER 'back'@'localhost' IDENTIFIED BY '123456'

GRANT SELECT, RELOAD, PROCESS, SHOW DATABASES, SUPER, LOCK TABLES, REPLICATION CLIENT ON . TO 'back'@'localhost'

SHOW GRANTS FOR back

REVOKE SELECT, INSERT, UPDATE, DELETE, EXECUTE ON sd_data.* FROM 'sdyc'@'%'

1、在opt目录里面新建两个文件夹

(1)mySoftware:用于存放软件安装包

(2)mysql:安装mysql的文件夹

2、解压mysql安装包:tar -xvf mysql-8.0.26-1.el7.x86_64.rpm-bundle.tar -C /opt/mysql

3、进入mysql目录,依次执行下面命令

4、启动MySQL服务

(1)systemctl start mysqld:启动mysql服务器

(2)systemctl restart mysqld:重启mysql服务器

(3)systemctl stop mysqld:停止mysql服务器

5、查询自动生成的root用户密码

6、修改root用户密码

登录到MySQL之后,需要将自动生成的不便记忆的密码修改了,修改成自己熟悉的便于记忆的密码。

ALTER USER 'root'@'localhost' IDENTIFIED BY '1234'

7、 默认的root用户只能当前节点localhost访问,是无法远程访问的,我们还需要创建一个root账户,用户远程访问

并给root用户分配权限

grant all on *.* to 'root'@'%'

首先要确保服务器上安装有MySQL,执行如下命令来检查是否安装了 MySQL(CentOS 7 上是 mariadb-server,CentOS 6 上是 mysql-server,这里以 CentOS 7 为例)

$ rpm -q mariadb-server

如果提示 package mariadb-server is not installed 则说明没有安装 MySQL,需要手动安装。如果出现 mariadb-server-xxx.xxx.xx.el7.x86_64 则说明已经安装。

安装 MySQL 的步骤为:

1.安装 MySQL 和 MySQL 客户端

$ sudo yum -y install mariadb mariadb-server

2.启动 MySQL

$ sudo systemctl start mariadb

3.设置开机启动

$ sudo systemctl enable mariadb

4.设置初始密码

$ sudo mysqladmin -u root password root

这时我们有两种方式来进行修改,这里只用了第一种,就直接将原来的 user='root' and host='localhost' 记录的host修改成%或指定的ip。

1.将host设置为%表示任何ip都能连接mysql

update user set host='%' where user='root' and host='localhost'

2.当然也可以将host指定为某个ip

update user set host='*.*.*.*' where user='root' and host='localhost'

这里将 . . . 换你实际的地址。

3.执行完以上语句,接着执行以下语句 ,刷新权限表,使配置生效

flush privileges

1.检查服务器防火墙3306端口开放了吗,没开放需要去开放

2.检查一下云平台的安全组规则中是否开放了3306端口,如何配置阿里云,这里以阿里云为例( 阿里云添加安全组规则 )


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/tougao/6076298.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-03-13
下一篇 2023-03-13

发表评论

登录后才能评论

评论列表(0条)

保存