银河麒麟系统安装mysql数据库
1.1 准备材料
mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz
MySQL5.7下载地址
https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz
1.1 安装前准备工作
1、检查是否已经安装MySQL
[root@localhost ~]# rpm -qa | grep mysql
2、将查询出的包卸载掉
[root@localhost ~]# rpm -e --nodeps
将/usr/lib64/libLLVM-7.so也一并删除
[root@localhost ~]# rm -rf /usr/lib64/libLLVM-7.so
4、检查是否删除成功
[root@localhost ~]# rpm -qa | grep mysql
5、查询残余文件夹
[root@localhost ~]# whereis mysql
6、删除残余文件
[root@localhost ~]# rm -rf /usr/bin/mysql /usr/share/man/man1/mysql.1.gz
7、验证删除结果
[root@localhost ~]# whereis mysql
8、检查MySQL用户组以及用户是否存在,若没有则创建
[root@localhost ~]# cat /etc/group | grep mysql
[root@localhost ~]# cat /etc/passwd |grep mysql
[root@localhost ~]# groupadd mysql
[root@localhost ~]# useradd -r -g mysql mysql
9、将mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz安装包上传到银河麒麟系统虚拟机中
10、开始安装MySQL数据库
#解压mysql数据库压缩包
[root@localhost 桌面]# tar -zxvf mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz
#复制解压后的mysql目录移动至/usr/local/mysql
[root@localhost 桌面]# cp -r mysql-5.7.28-linux-glibc2.12-x86_64 /usr/local/mysql
在目录下/usr/local/mysql/创建data目录
[root@localhost ~]# mkdir /usr/local/mysql/data
更改MySQL目录下所有的目录文件夹所属组和用户以及权限
[root@localhost ~]# chown -R mysql:mysql /usr/local/mysql
[root@localhost ~]# chmod -R 755 /usr/local/mysql
1)修改权限之前:
2)修改权限之后:
修改MySQL的数据配置文件vim /etc/my.cnf ,修改完后内容如下
来使用vim打开该文件,然后按一下i进入INSERT更改模式,使用小键盘旁边的上下左右按键可以移动光标位置,移动到想到的位置进行正常的增删操作,在操作完毕后,按Ctrl+C结束INSERT模式,再输入:wq再按回车即可退出。
或者
|
注意socket的值必须前后一致,否则会报错:Can’t connect to local MySQL server through socket的解决方法
11、编译安装并初始化MySQL数据库,并记录初始化后末尾输出的默认密码
[root@localhost ~]# cd /usr/local/mysql/bin
读取密码
[root@localhost bin]# ./mysqld --initialize --user=mysql --datadir=/usr/local/mysql/data --basedir=/usr/local/mysql
以上步骤执行完成后生产的临时密码,该数据库密码:ab)8xkZTi4XD
[root@localhost bin]# ./mysqld --initialize --user=mysql --datadir=/usr/local/mysql/data --basedir=/usr/local/mysql
2023-02-17T06:33:04.515456Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2023-02-17T06:33:05.303844Z 0 [Warning] InnoDB: New log files created, LSN=45790
2023-02-17T06:33:05.413152Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2023-02-17T06:33:05.486498Z 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: ef7ba16f-ae8c-11ed-877c-000c29cb2878.
2023-02-17T06:33:05.487709Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2023-02-17T06:33:05.947457Z 0 [Warning] CA certificate ca.pem is self signed.
2023-02-17T06:33:06.086861Z 1 [Note] A temporary password is generated for root@localhost: ab)8xkZTi4XD
12、添加开机自启并开启服务
[root@localhost bin]# cp -rf /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
1)在拷贝前,support-files目录
2)在拷贝前,/etc/init.d目录
3)在拷贝后,/etc/init.d目录
[root@localhost bin]# chmod +x /etc/init.d/mysqld
a)在执行付权限前后的变化:
[root@localhost bin]# systemctl enable mysqld
[root@localhost bin]# /usr/lib/systemd/systemd-sysv-install enable mysqld
添加环境变量【环境变量文件:/etc/profile】,在空白处添加以下代码
export MYSQL_HOME=/usr/local/mysql
export PATH=$PATH:$MYSQL_HOME/bin
[root@localhost bin]# vim /etc/profile
使环境变量生效
[root@localhost bin]# source /etc/profile
开启MySQL服务[cd /usr/local/mysql/bin]
[root@localhost bin]# systemctl start mysqld
查询服务状态
[root@localhost bin]# systemctl status mysqld
使用默认密码登录数据库
[root@localhost bin]# mysql -u root -p
输入密码:ab)8xkZTi4XD
至此MySQL安装完成
13、修改密码:
mysql> set password for root@localhost = password('mysql123');