下载
https://downloads.mysql.com/archives/community/
解压
tar -xf mysql-5.7.39-linux-glibc2.12-x86_64.tar.gz
创建linux用户和组
groupadd mysql && useradd -r -g mysql mysql
设置
注意,以下示例步骤中安装mysql的位置为/usr/local/mysql
,mysql数据文件夹为/usr/local/mysql/data
vim /etc/my.cnf
参考:http://c.biancheng.net/view/7618.html
这儿的不要乱写,容易导致各种奇奇怪怪的问题
[mysqld] port=3306 user=mysql basedir=/usr/local/mysql datadir=/usr/local/mysql/data socket=/tmp/mysql.sock max_connections=200 symbolic-links=0 character-set-server=utf8 default-storage-engine=INNODB sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES [mysql] default-character-set=utf8 [mysqld_safe] log-error=/usr/local/mysql/error.log pid-file=/usr/local/mysql/mysqld.pid
文档:https://www.mysqlzh.com/doc/13/78.html
# 创建数据文件夹, 日志文件夹, 设置所有者 cd /usr/local/mysql && mkdir logs && touch error.log && chown mysql:mysql -R *
初始化
bin/mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/ --user=mysql --initialize
解决./mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
sudo apt install -y libaio-dev numactl
复制 mysql 到系统服务
cp support-files/mysql.server /etc/init.d/mysql
解决Unit mysql.service does not exist, proceeding anyway.
修改vim /etc/init.d/mysql
# 若/etc/my.cnf中指定了mysql目录,则此处也需要指定 basedir=/usr/local/mysql datadir=/usr/local/mysql/data
启动mysql
systemctl enable mysql
或者
service mysql start
进入mysql命令行
mysql -u root -p # 在接下来的一行中输入密码
解决./mysql: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory
apt-get install -y libncurses*
修改密码
-- 更新密码 alter user 'user'@'host' identified by 'password'; -- 刷新权限 flush privileges;
常用操作
以下内容参考于 https://blog.csdn.net/qpzkobe/article/details/102833458
# 创建用户 username替换为用户名, host替换为地址, password替换为密码 # 示例 CREATE USER 'mc'@'localhost' IDENTIFIED BY '123456'; CREATE USER 'username'@'host' IDENTIFIED BY 'password'; # 删除用户 username替换为用户名, host替换为地址 # 示例 DROP USER 'mc'@'localhost'; DROP USER 'username'@'host'; # 授权 privileges替换为权限, databasename替换为库名, tablename替换为表名, username替换为用户名, host替换为地址 # 示例 GRANT all ON playerpoints.* TO 'mc'@'localhost'; GRANT privileges ON databasename.tablename TO 'username'@'host'; # 撤销授权 privileges替换为权限, databasename替换为库名, tablename替换为表名, username替换为用户名, host替换为地址 # 示例 REVOKE all ON playerpoints.* FROM 'mc'@'localhost'; REVOKE privilege ON databasename.tablename FROM 'username'@'host'; # 刷新权限 flush privileges;