MySQL5.7.23地址:https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz
上述地址有可能根据官网更新失效,也可以去官网下载,选择对应的操作系统以及一些参数。
官网地址:https://dev.mysql.com/downloads/mysql/5.7.html#downloads
环境:
操作系统 | Centos 7.2 |
MySQL版本号 | 5.7.23 |
下载:
wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz
解压安装:
[root@node1 ~]# tar -xf mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz
[root@node1 ~]# mkdir /usr/local/mysql
[root@node1 ~]# mkdir /usr/local/mysql/data
[root@node1 ~]# mv mysql-5.7.23-linux-glibc2.12-x86_64/* /usr/local/mysql/
[root@node1 ~]# groupadd mysql
[root@node1 ~]# useradd -g mysql mysql
[root@node1 ~]# chown -R mysql.mysql /usr/local/mysql
[root@node1 ~]# /usr/local/mysql/bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/
[root@node1 ~]# cp -a /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@node1 ~]# vim /etc/my.cnf
#将原来内容删除,下列内容复制进去,注意我的数据直接存放在mysql目录下的data中。如果需要修改在下面datadir中修改就可以。
# 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]
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
# These are commonly set, remove the # and set as required.
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
port = 3306
lower_case_table_names=1
# server_id = .....
socket = /tmp/mysql.sock
character-set-server = utf8
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
[root@node1 ~]# service mysqld start
[root@node1 ~]# ss -tannl
LISTEN 0 80 :::3306 :::*
LISTEN 0 128 :::111 :::*
LISTEN 0 128 :::22 :::*
登录
[root@node1 ~]# cat /root/.mysql_secret
ThlZ,jukf8(+ #获得登录用户密码
[root@node1 ~]# /usr/local/mysql/bin/mysql -uroot -p
Enter password: #把刚才密码粘贴过来
mysql> #登录成功。
MySQL一些设置
修改密码:
mysql> SET PASSWORD FOR 'root'@localhost = PASSWORD('123456');
Query OK, 0 rows affected, 1 warning (0.00 sec)
#将密码修改为 123456
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
#刷新权限
添加远程用户(用户root 密码123456 %代表允许远程登录):
mysql> grant all privileges on *.* to 'root'@'%' identified by '123456' with grant option;
Query OK, 0 rows affected, 1 warning (0.00 sec)
#添加一个可以远程访问的用户,对所有数据库都有任何权限。
%代表可以远程 localhost代表只能本地访问。
*.*代表所有数据库所有权限 test.* 代表test库下所有权限。
查询mysql用户:
mysql> use mysql
mysql> select user,host from user;
+---------------+-----------+
| user | host |
+---------------+-----------+
| root | % |
| mysql.session | localhost |
| mysql.sys | localhost |
| root | localhost |
+---------------+-----------+
其中%代表允许外网访问,localhost代表只允许本地访问。
查询mysql版本:
mysql> select version();
+-----------+
| version() |
+-----------+
| 5.7.23 |
+-----------+
1 row in set (0.00 sec)
本博客是参照很多博客实践总结而来,转发请附带链接,敬礼!change the world~