RedHat MySQL数据库安装
1.5.MySQL数据库安装1.5.1.linux下MySQL安装https://dev.mysql.com/downloads/mysql/5.7.html这里我们下载mysql-5.7 64位版本。6、上传安装包解压缩安装tar -xvf mysql-5.7.32-linux-glibc2.12-x86_64.tar.gz7、将解压缩后目录重命名并移动目录mv mysql-5.7.32-lin
1.5.MySQL数据库安装
1.5.1.linux下MySQL安装
https://dev.mysql.com/downloads/mysql/5.7.html
这里我们下载mysql-5.7 64位版本。
6、上传安装包解压缩安装
tar -xvf mysql-5.7.32-linux-glibc2.12-x86_64.tar.gz
7、将解压缩后目录重命名并移动目录
mv mysql-5.7.32-linux-glibc2.12-x86_64 /usr/local/mysql
8、创建mysql用户组和用户并修改权限
groupadd mysql
useradd -r -g mysql mysql
创建数据目录并赋予权限
mkdir -p /usr/local/mysql/data
chown mysql:mysql -R /usr/local/mysql/data
9、修改配置文件
打开配置文件 vim /etc/my.cnf 在 mysqld 下新增一行 lower_case_table_names=1 ,表示不区分大小写。修改datadir数据存储目录
说明 0:区分大小写,1:不区分大小写
10、初始化数据库
进入mysql的bin目录cd /usr/local/mysql/bin/
执行数据初始化命令:
./mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data --user=mysql --initialize
[Note] A temporary password is generated for root@localhost: OU_i+)p#<8%S
初始化完成后,可以看到有登陆密码。
11、修改/etc/my.cnf配置文件
[root@bogon ~]# vim /etc/my.cnf
[mysqld]
bind-address=0.0.0.0
port=3306
user=mysql
basedir=/usr/local/mysql
datadir=/var/lib/mysql
socket=/var/lib/mysql/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
explicit_defaults_for_timestamp=true
[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
[client]
port=3306
socket=/var/lib/mysql/mysql.sock
[root@bogon ~]#
12、将mysql启动文件拷贝到系统启动目录
先将mysql.server放置到/etc/init.d/mysql中。
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
13、启动服务
service mysql start
service mysql status
ps -ef|grep mysql
14、登陆mysql,更改root 密码
mysql -u root -p
再执行下面三步操作,然后重新登录。
SET PASSWORD = PASSWORD(‘123456’);
ALTER USER ‘root’@‘localhost’ PASSWORD EXPIRE NEVER;
FLUSH PRIVILEGES;
远程登录:
mysql -h 47.107.186.110 -P3306 -uroot -pDszn@2020
15、修改密码
update user set password=password(‘123’) where user=‘root’ and host=‘localhost’;
flush privileges;
修改完成后重启mysql,然后进行客户端连接测试
16、客户端测试
1、客户端安装
mysql客户端 navicat111_premium_cs_x86_11.1.14.0.1453198735.exe
Navicat Premium11破解注册机.zip
首先安装navicat111_premium_cs_x86_11.1.14.0.1453198735.exe,直接点击安装,傻瓜式操作,不需要任何配置。
安装完成后,点击注册机运行,提示破解成功即可。
2、客户端连接
安装mysql客户端完后后,点击文件-》新增-》msyql-》输入mysql地址,用户、密码,点击连接测试,提示连接成功即可。
1.5.2.Mysql操作异常
1、初始化mysql异常提示:
[root@watch bin]#
oot@watch bin]# ./mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data --user=mysql --initialize
2020-11-17T05:40:02.512303Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2020-11-17T05:40:02.512418Z 0 [Warning] ‘NO_ZERO_DATE’, ‘NO_ZERO_IN_DATE’ and ‘ERROR_FOR_DIVISION_BY_ZERO’ sql modes should be used with strict mode. They will be merged with strict mode in a future release.
2020-11-17T05:40:02.512423Z 0 [Warning] ‘NO_AUTO_CREATE_USER’ sql mode was not set.
2020-11-17T05:40:03.474271Z 0 [Warning] InnoDB: New log files created, LSN=45790
2020-11-17T05:40:03.605607Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2020-11-17T05:40:03.669436Z 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: 576a60ed-2897-11eb-8f35-00163e02ac96.
2020-11-17T05:40:03.671838Z 0 [Warning] Gtid table is not ready to be used. Table ‘mysql.gtid_executed’ cannot be opened.
2020-11-17T05:40:04.600819Z 0 [Warning] CA certificate ca.pem is self signed.
2020-11-17T05:40:04.849068Z 1 [Note] A temporary password is generated for root@localhost: dlZg=vJ:e5QC
[root@watch bin]#
解决方法:
1、在 vi /etc/my.cnf 文件中[mysqld]加上 : explicit_defaults_for_timestamp=true 。保存后再次启动就可以了。
2、登陆异常
2、登陆异常:
[root@bogon bin]# ./mysql -uroot -p
Enter password:
ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ (2)
[root@bogon bin]#
建立软链接: ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock ,重启mysql即可
3、启动服务异常:
[root@bogon mysql]# service mysql start
Starting MySQL.2020-11-18T06:51:57.343473Z mysqld_safe error: log-error set to ‘/var/log/mariadb/mariadb.log’, however file don’t exists. Create writable for user ‘mysql’.
ERROR! The server quit without updating PID file (/var/lib/mysql/bogon.pid).
[root@bogon mysql]#
解决办法:
因为没有路径也没有权限,所以创建此路径并授权给mysql用户
mkdir /var/log/mariadb
touch /var/log/mariadb/mariadb.log
用户组及用户
chown -R mysql:mysql /var/log/mariadb/
/usr/local/mysql/support-files/mysql.server start
4、客户端连接提示不允许连接或者提示localhost没有权限等等,需要进行如下修改,修改ip地址不限制。
.use mysql #访问mysql库
.update user set host = ‘%’ where user = ‘root’; #使root能再任何host访问
.FLUSH PRIVILEGES;
更多推荐
所有评论(0)