CentOS 7.6 64位安装Mysql

首先到官网下载:https://dev.mysql.com/downloads/mysql/

创建文件夹software 上传mysql.tar.xz(这里我将文件重命名了一下)

通过工具:WinSCP上传

服务端查询显示结果:

解压mysql.tar.xz

[root@VM_0_6_centos software]# xz -d mysql.tar.xz           //解压mysql.tar.xz
[root@VM_0_6_centos software]# ll                           //再次查询             
total 2438196
-rw-r--r-- 1 root root 2518545920 Jul 12 14:20 mysql.tar    //查询结果
[root@VM_0_6_centos software]# tar -xvf mysql.tar           //解压mysql.tar
mysql-8.0.16-linux-glibc2.12-x86_64/bin/                    //.......
mysql-8.0.16-linux-glibc2.12-x86_64/bin/myisam_ftdump
mysql-8.0.16-linux-glibc2.12-x86_64/bin/myisamchk
[root@VM_0_6_centos software]# ll  //再次查询
total 2438200
drwxr-xr-x 11 root root       4096 Jul 13 10:56 mysql-8.0.16-linux-glibc2.12-x86_64
-rw-r--r--  1 root root 2518545920 Jul 12 14:20 mysql.tar

将解压后的文件名改名为mysql,并移至/usr/local/目录下

[root@VM_0_6_centos software]# mv mysql-8.0.16-linux-glibc2.12-x86_64 /usr/local/mysql

再创建用户和用户组

[root@VM_0_6_centos local]# groupadd mysql
[root@VM_0_6_centos local]# useradd -r -g mysql mysql

将安装目录所有者及所属组改为mysql ,这个根据自己的目录来

[root@VM_0_6_centos local]# chown -R mysql.mysql /usr/local/mysql

在mysql目录下创建data文件夹

[root@VM_0_6_centos local]# cd mysql
[root@VM_0_6_centos mysql]# mkdir data

初始化数据库(这里出现了一个错误)

./mysqld --initialize --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data

已下为腾讯云:

[root@VM_0_6_centos bin]# ./mysqld --initialize --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data
./mysqld: error while loading shared libraries: libnuma.so.1: cannot open shared object file: No such file or directory
[root@VM_0_6_centos bin]#

  运行命令:yum -y install numactl (应该是下一个东西)

[root@VM_0_6_centos bin]# yum -y install numactl
Loaded plugins: fastestmirror, langpacks                //部分运行的效果
Determining fastest mirrors
Resolving Dependencies   
--> Running transaction check
---> Package numactl.x86_64 0:2.0.9-7.el7 will be installed
--> Processing Dependency: libnuma.so.1(libnuma_1.4)(64bit) for package: numactl-2.0.9-7.el7.x86_64.....

已下为阿里云:

[root@iz2zejb8ayql48hozpjvnzz bin]# ./mysqld --initialize --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data
./mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
[root@iz2zejb8ayql48hozpjvnzz bin]#

 运行命令:yum search libaio

[root@iz2zejb8ayql48hozpjvnzz bin]# yum search libaio
Loaded plugins: fastestmirror
base           .....

再运行命令: yum install libaio

[root@iz2zejb8ayql48hozpjvnzz bin]# yum install libaio
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Resolving Dependencies ......

再次执行:./mysqld --initialize --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data

编辑配置文件my.cnf

完成初始化后编辑配置文件 /etc/my.cnf

#若系统中无/etc/my.cnf文件,则需要创建
[root@VM_0_6_centos bin]# touch /etc/my.cnf
[root@VM_0_6_centos bin]# vim /etc/my.cnf

键盘点击 i 开始编辑

[mysqld]
datadir=/usr/local/mysql/data
basedir=/usr/local/mysql
socket=/tmp/mysql.sock
user=mysql
port=3306
character-set-server=utf8
# 取消密码验证
skip-grant-tables
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# skip-grant-tables
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

退出:点击键盘esc 然后输入 :wq  保存 (不保存输入:q!)(冒号也是指令的一部分)

将mysql加入到服务

[root@VM_0_6_centos bin]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql

开机启动

[root@VM_0_6_centos bin]# chkconfig mysql on

启动mysql

[root@VM_0_6_centos bin]# service mysql start
Starting MySQL.. SUCCESS! 
[root@VM_0_6_centos bin]#

mysql -u root -p  或者   /usr/local/mysql/bin/mysql -uroot -p

使用第二个命令是没有配置环境变量

export PATH=$PATH:/usr/local/mysql/bin

没用试试: ln -s  /usr/local/mysql/bin/mysql  /usr/bin

[root@VM_0_6_centos bin]# mysql -u root -p                      
-bash: mysql: command not found
[root@VM_0_6_centos bin]# export PATH=$PATH:/usr/local/mysql/bin   
[root@VM_0_6_centos bin]# mysql -u root -p
Enter password:                                           //配置文件设置了这里直接回车跳过密码
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 8.0.16 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> 

 修改密码 

update user set authentication_string=password('你的密码') where user='root';

或者 set password=password("密码");

如果报错 用:flush privileges; 更改一下权限 ,然后:ALTER USER 'root'@'localhost' identified by '密码' ;

mysql> flush privileges;
Query OK, 0 rows affected (0.03 sec)

mysql> ALTER USER 'root'@'localhost' identified by '123456';
Query OK, 0 rows affected (0.01 sec)

mysql>

 设置可以远程连接

mysql> 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
mysql> update user set host='%' where user = 'root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

mysql> exit
Bye
[root@VM_0_6_centos bin]#

参考:https://blog.csdn.net/weixin_42734930/article/details/81743047

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值