Linux安装mysql

1.卸载已经安装 Mysql

#查看 已安装mysql 
[root@instance-bg3s0btb ~]# rpm -qa | grep mysql
#卸载 已安装mysql   xx文件名
[root@instance-bg3s0btb ~]# rpm -e xx

#找出OS中分散的mysql文件夹
find / -name mysql
 
#rm -rf --注意每个绝对路径中间用空格隔开
rm -rf  /data/mysql/mysql   /usr/lib64/mysql  /usr/local/mysql  /usr/local/mysql/include/mysql /usr/local/mysql/bin/mysql  /usr/share/mysql

2.下载官方 mysql包 

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

选择Linux通用版

 3.解压文件并文件移动到/usr/local/mysql (默认安装路径)

#-z 是否同时具有gz属性
#-x 解压缩、提取打包的内容(解压)
#-v 显示压缩或者打包的内容
#-f 使用文件名,在f后面要接压缩后的文件的名字,只要用到tar命令,-f选项是必须要用的,-f参数在使用
#的时候一定排在其他参数的后面,在最右边
tar -zxvf mysql-5.7.35-linux-glibc2.12-x86_64.tar.gz
#移动文件到 /usr/local/mysql
mv mysql-5.7.35-linux-glibc2.12-x86_64 /usr/local/mysql

cd /usr/local/mysql

ll
drwxr-xr-x  2 root root    4096 12月  8 13:05 bin
drwxr-xr-x  2 root root    4096 12月  8 13:05 docs
drwxr-xr-x  3 root root    4096 12月  8 13:04 include
drwxr-xr-x  5 root root    4096 12月  8 13:05 lib
-rw-r--r--  1 7161 31415 259200 6月   7 2021 LICENSE
drwxr-xr-x  4 root root    4096 12月  8 13:05 man
-rw-r--r--  1 7161 31415    566 6月   7 2021 README
drwxr-xr-x 28 root root    4096 12月  8 13:05 share
drwxr-xr-x  2 root root    4096 12月  8 13:05 support-files

4.添加环境变量


echo "export PATH=/usr/local/mysql/bin:$PATH" >> /etc/profile
  
source /etc/profile


cat /etc/profile | grep /mysql

export PATH=/usr/local/mysql/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin

5.添加用户mysql  创建数据目录   给用户授权

useradd mysql

mkdir -p /data/mysql

chown -R mysql.mysql /usr/local/mysql/*

6.始化数据(初始化之后会生成一个密码,一定要记下来,等会需要登录)

#mysqld:管理mysql的命令
#–initialize-insecure 初始化数据
#–user=mysql 管理数据库的用户
#basedir=/usr/local/mysql 软件程序的位置
#–datadir=/data/mysql 数据存放的位置
[root@instance-bg3s0btb mysql]#  mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql
2022-12-08T05:29:33.705036Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-12-08T05:29:34.559083Z 0 [Warning] InnoDB: New log files created, LSN=45790
2022-12-08T05:29:34.681812Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2022-12-08T05:29:34.744631Z 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: 4cc651ce-76b9-11ed-91ba-fa202022e5cd.
2022-12-08T05:29:34.746259Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2022-12-08T05:29:36.101502Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2022-12-08T05:29:36.101519Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2022-12-08T05:29:36.102082Z 0 [Warning] CA certificate ca.pem is self signed.
2022-12-08T05:29:36.270101Z 1 [Note] A temporary password is generated for root@localhost: NMg7u=B_M-Ak

7.添加配置文件 /etc/my.cnf 

 vim /etc/my.cnf
 
[mysqld]
user=mysql
basedir=/usr/local/mysql
datadir=/data/mysql
port=3306
socket=/tmp/mysql.sock
[mysql]
socket=/tmp/mysql.sock
prompt=3306 [\\d]>

 8. 启动mysql   
 

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

#重启服务    
service mysql restart

9.登陆数据库 修改密码 设置 远程登陆

# 登陆数据库 密码为 初始化后的密码
[root@instance-bg3s0btb etc]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.7.35

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

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.

3306 [(none)]> alter user 'root'@'localhost' identified by '123456'; 

3306 [(none)]> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
3306 [mysql]>select User,Host from user;
+---------------+-----------+
| User          | Host      |
+---------------+-----------+
| mysql.session | localhost |
| mysql.sys     | localhost |
| root          | localhost |
+---------------+-----------+
3 rows in set (0.00 sec)

3306 [mysql]>update user set host = '%' where user = 'root'; 
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

3306 [mysql]>select User,Host from user;
+---------------+-----------+
| User          | Host      |
+---------------+-----------+
| root          | %         |
| mysql.session | localhost |
| mysql.sys     | localhost |
+---------------+-----------+
3 rows in set (0.00 sec)

3306 [mysql]>flush privileges;
Query OK, 0 rows affected (0.00 sec)


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值