CentOS6安装MySQL5.7.28数据库
说明
本文主要记录如何在Linux服务器安装一个MySQL数据库,希望本文可以帮助到一些刚入门的童鞋。
下载不需要编译的包
这里使用的操作系统是CentOS6,64位操作系统。
$ wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz
解压部署指定目录
$ tar zxf mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz$ mkdir -p ~/3rd/mysql-5.7.28$ mv mysql-5.7.28-linux-glibc2.12-x86_64/* ~/3rd/mysql-5.7.28
创建数据目录和日志目录
数据目录和日志目录可以提前创建,如:
$ mkdir /home/testerzhang/3rd/mysql-5.7.28/data/$ mkdir /home/testerzhang/3rd/mysql-5.7.28/log/
初始化data
假设当前用户名是testerzhang,指定安装目录
$ cd ~/3rd/mysql-5.7.28$ ./bin/mysql_install_db --user=testerzhang --basedir=/home/testerzhang/3rd/mysql-5.7.28 --datadir=/home/testerzhang/3rd/mysql-5.7.28/data
日志输出
2019-10-31 12:30:59 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize2019-10-31 12:31:20 [WARNING] The bootstrap log isn't empty:2019-10-31 12:31:20 [WARNING] 2019-10-31T04:30:59.852748Z 0 [Warning] --bootstrap is deprecated. Please consider using --initialize instead2019-10-31T04:30:59.853622Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 5000)2019-10-31T04:30:59.853634Z 0 [Warning] Changed limits: table_open_cache: 431 (requested 2000)
创建配置文件
$ vim bin/my.cnf [mysqld]datadir=/home/testerzhang/3rd/mysql-5.7.28/databasedir=/home/testerzhang/3rd/mysql-5.7.28socket=/home/testerzhang/3rd/mysql-5.7.28/bin/mysql.sockuser=testerzhangport=3306character-set-server=utf8
#跳过密码验证,忘记密码 可以设置,然后修改密码,再关闭skip-grant-tables
# Disabling symbolic-links is recommended to prevent assorted security riskssymbolic-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
[mysqld_safe]
log-error=/home/testerzhang/3rd/mysql-5.7.28/log/mysqld.logpid-file=/home/testerzhang/3rd/mysql-5.7.28/bin/mysqld.pid
写个启动脚本
$ cd ~/3rd/mysql-5.7.28/bin$ vim startmysql.sh ./mysqld_safe --defaults-file=./my.cnf &
$ sh -x startmysql.sh
初次设置root密码
$ mysql -h127.0.0.1 -P3306 -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 2Server version: 5.7.28 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 itsaffiliates. Other names may be trademarks of their respectiveowners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> use mysql;Reading table information for completion of table and column namesYou can turn off this feature to get a quicker startup with -A
Database changedmysql> update user set authentication_string=password('具体密码') where user='root'; Query OK, 1 row affected, 1 warning (0.00 sec)Rows matched: 1 Changed: 1 Warnings: 1
mysql> flush privileges;Query OK, 0 rows affected (0.01 sec)
mysql> exitBye
修改密码后再次登录设置root密码
mysql> use mysqlERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> alter user 'root'@'localhost' identified by '具体密码';Query OK, 0 rows affected (0.00 sec)mysql> flush privileges;mysql> exit;
设置root可以远程被连接
如果不需要配置数据库root用户远程连接,可以跳过此步骤。
mysql> use mysqlmysql> update user set host='%' where user = 'root';mysql> flush privileges;mysql> exit;
创建普通用户
如创建一个test用户,密码为test123,可以进行远程登录:
mysql> grant all privileges on test.* to 'test'@'%' identified by 'test123';mysql> flush privileges;mysql> exit;
是不是很简单?相信你学会了。
欢迎关注我的公众号“testerzhang”,原创技术文章第一时间推送。
领取专属 10元无门槛券
私享最新 技术干货