Linux安装MySQL
安装分为两种方式:
一、rpm安装
1.1 首先查看服务器的版本
cat /proc/version
然后下载对应版本的rpm安装包
1.2
二、tar.gz包安装
2.1 首先上传tar.gz包到服务器,并解压,
tar -zxvf
如下图所示:
2.2 查看是否安装MySQL及相关的
rpm -qa | grep mysql
rpm -qa | grep mariadb
如果存在,则进行卸载
rpm -e mysql-libs-5.1.52-1.el6_0.1.x86_64 // 普通删除模式 rpm -e --nodeps mysql-libs-5.1.52-1.el6_0.1.x86_64 // 强力删除模式,如果使用上面命令删除时,提示有依赖的其它文件,则用该命令可以对其进行强力删除
2.3 安装MySQL
2.3.1 添加系统mysql组和mysql用户
检查mysql组和用户是否存在,如无创建,下面的存在的情况
cat /etc/group | grep mysql ### mysql:x:1001: cat /etc/passwd | grep mysql ### mysql:x:995:1001::/home/mysql:/bin/bash
如果不存在,则进行创建
groupadd mysql useradd -r -g mysql mysql #useradd -r参数表示mysql用户是系统用户,不可用于登录系统
2.3.2 安装数据库
创建Data目录:
给目录赋予权限
chown -R mysql.mysql /data/mysql/mysql-5.7.29
在./support-files目录下创建my_default.cnf ,内容如下(目录改为自己的):
# For advice on how to change settings please see # http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html # *** DO NOT EDIT THIS FILE. It's a template which will be copied to the # *** default location during install, and will be replaced if you # *** upgrade to a newer version of MySQL. [mysqld] sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES basedir = /data/mysql/mysql-5.7.29 datadir = /data/mysql/mysql-5.7.29/data port = 3306 socket = /tmp/mysql.sock character-set-server=utf8 log-error = /data/mysql/mysql-5.7.29/data/mysqld.log pid-file = /data/mysql/mysql-5.7.29/data/mysqld.pid
拷贝,如果提示是否覆盖,(备份后覆盖) y
cp support-files/my_default.cnf /etc/my.cnf
初始化 mysqld(目录改为自己的)
./bin/mysqld --initialize --user=mysql --basedir=/data/mysql/mysql-5.7.29/ --datadir=/data/mysql/mysql-5.7.29/data/
初始化完成之后,查看日志,然后拷贝密码:
/data/mysql/mysql-5.7.29/data/mysqld.log
设置脚本开机启动
cp support-files/mysql.server /etc/init.d/mysql
service mysql start // 启动MySQL服务
如果是升级mysql,记得kill之前的mysql,然后启动新的mysql
进入MySQL,修改密码:
[root@VM_0_6_centos bin]# cd /data/mysql/mysql-5.7.29/bin/ [root@VM_0_6_centos bin]# ./mysql -u root -p Enter password:
mysql> set password=password('beishang886'); Query OK, 0 rows affected, 1 warning (0.00 sec) mysql> grant all privileges on *.* to root@'%' identified by 'beishang886'; Query OK, 0 rows affected, 1 warning (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) mysql>
安装成功,
查看所有用户
use mysql; select User,Host,authentication_string from user;
遇到问题汇总
[root@VM-0-12-centos bin]# ./mysqld --initialize --user=mysql --basedir=/data/mysql/mysql-5.7.29/ --datadir=/data/mysql/mysql-5.7.29/data/ ./mysqld: error while loading shared libraries: libnuma.so.1: cannot open shared object file: No such file or directory
解决:
如果安装mysql出现了以上的报错信息.这是却少numactl
这个时候如果是Centos就yum -y install numactl
就可以解决这个问题了.
ubuntu的就sudo apt-get install numactl
就可以解决这个问题了
select host,user,authentication_string from mysql.user; create user 'yunnn'@'%' identified by 'yunnn123'; grant all privileges on `yunnan`.* to 'yunnn'@'%' ; grant all privileges on `test`.* to 'yunnn'@'%' ; flush privileges; show grants; -- 1044 打开授权权限 UPDATE mysql.user SET Grant_priv='Y', Super_priv='Y' WHERE User='root'; SELECT VERSION()
分配mysql用户权限
select host,user,authentication_string from mysql.user; grant all privileges on `guangxicp_test`.* to 'qgjszctest'@'%' ;
https://blog.csdn.net/yhj198927/article/details/103745946
https://blog.csdn.net/hjf161105/article/details/78850658
https://www.cnblogs.com/chuanqi1995/p/11325400.html
参考文献:
https://blog.csdn.net/lch520baby/article/details/89081306#commentBox