版本centos7,4个mysql5.7rpm包
(mysql6.8版本安装mysql5.7会出各种问题)
1.cd /opt
2.拷贝四个rpm包
分别为mysql-community-client-5.7.16-1.el7.x86_64.rpm
mysql-community-common-5.7.16-1.el7.x86_64.rpm
mysql-community-libs-5.7.16-1.el7.x86_64.rpm
mysql-community-server-5.7.16-1.el7.x86_64.rpm
3.先查看是否之前自带有版本
rpm -qa |grep -i mariadb (对于centos7来说,mariadb,6来说是mysql)
rpm -e --nodeps mariadb-libs-5.5.60-1.el7_5.x86_64
查到有结果后,需要卸载
4.卸载已经安装过得版本包
rpm -e --nodeps mariadb-libs-5.5.60-1.el7_5.x86_64
5.开始安装
安装有依赖关系,安装顺序
rpm -ivh mysql-community-common-5.7.16-1.el7.x86_64.rpm --force --nodeps
rpm -ivh mysql-community-libs-5.7.16-1.el7.x86_64.rpm --force --nodeps
rpm -ivh mysql-community-client-5.7.16-1.el7.x86_64.rpm --force --nodeps
rpm -ivh mysql-community-server-5.7.16-1.el7.x86_64.rpm --force --nodeps
安装完成后,需要yum install libaio ,安装依赖环境
6.安装完成后
查看版本 mysql --version
初始化 mysqld --initialize --user=mysql
启动 systemctl start mysqld.service
关闭 systemctl stop mysqld.service
重启 systemctl restart mysqld.service
查看是否启动成功 systemctl status mysqld.service
mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since Sun 2019-07-28 10:20:16 CST; 18min ago
Process: 5004 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
Process: 4987 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 5007 (mysqld)
CGroup: /system.slice/mysqld.service
└─5007 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
Jul 28 10:20:16 ecs-s6-medium-2-linux-20190723153302 systemd[1]: Starting MySQL Server...
Jul 28 10:20:16 ecs-s6-medium-2-linux-20190723153302 systemd[1]: Started MySQL Server.
查看初始密码:cat /var/log/mysqld.log
2019-07-28T02:19:44.707183Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-07-28T02:19:44.855964Z 0 [Warning] InnoDB: New log files created, LSN=45790
2019-07-28T02:19:44.894039Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2019-07-28T02:19:44.954239Z 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: 2a3f7ab2-b0de-11e9-b708-fa163eb95d37.
2019-07-28T02:19:44.956712Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2019-07-28T02:19:44.957000Z 1 [Note] A temporary password is generated for root@localhost: L=s,z.CVa0Ze
2019-07-28T02:20:16.578157Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-07-28T02:20:16.579213Z 0 [Note] /usr/sbin/mysqld (mysqld 5.7.16) starting as process 5007 ...
2019-07-28T02:20:16.581573Z 0 [Note] InnoDB: PUNCH HOLE support available
2019-07-28T02:20:16.581597Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2019-07-28T02:20:16.581600Z 0 [Note] InnoDB: Uses event mutexes
2019-07-28T02:20:16.581603Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
2019-07-28T02:20:16.581605Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.3
2019-07-28T02:20:16.581608Z 0 [Note] InnoDB: Using Linux native AIO
2019-07-28T02:20:16.581818Z 0 [Note] InnoDB: Number of pools: 1
2019-07-28T02:20:16.581905Z 0 [Note] InnoDB: Using CPU crc32 instructions
2019-07-28T02:20:16.583047Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
2019-07-28T02:20:16.589762Z 0 [Note] InnoDB: Completed initialization of buffer pool
2019-07-28T02:20:16.594116Z 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
2019-07-28T02:20:16.605634Z 0 [Note] InnoDB: Highest supported file format is Barracuda.
2019-07-28T02:20:16.613250Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
2019-07-28T02:20:16.613276Z 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
2019-07-28T02:20:16.630144Z 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
2019-07-28T02:20:16.630728Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.
2019-07-28T02:20:16.630736Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active.
2019-07-28T02:20:16.630882Z 0 [Note] InnoDB: Waiting for purge to start
2019-07-28T02:20:16.680992Z 0 [Note] InnoDB: 5.7.16 started; log sequence number 2532034
2019-07-28T02:20:16.681210Z 0 [Note] Plugin 'FEDERATED' is disabled.
2019-07-28T02:20:16.684643Z 0 [Warning] Failed to set up SSL because of the following SSL library error: SSL context is not usable without certificate and private key
2019-07-28T02:20:16.684896Z 0 [Note] Server hostname (bind-address): '*'; port: 3306
2019-07-28T02:20:16.684924Z 0 [Note] IPv6 is available.
2019-07-28T02:20:16.684932Z 0 [Note] - '::' resolves to '::';
2019-07-28T02:20:16.684946Z 0 [Note] Server socket created on IP: '::'.
2019-07-28T02:20:16.685081Z 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
2019-07-28T02:20:16.686222Z 0 [Note] InnoDB: Buffer pool(s) load completed at 190728 10:20:16
2019-07-28T02:20:16.692588Z 0 [Note] Event Scheduler: Loaded 0 events
2019-07-28T02:20:16.692703Z 0 [Note] /usr/sbin/mysqld: ready for connections.
Version: '5.7.16' socket: '/var/lib/mysql/mysql.sock' port: 3306 MySQL Community Server (GPL)
7.登录 mysql -uroot -p
[root@ecs-s6-medium-2-linux-20190723153302 opt]# mysql -uroot -p
Enter password: L=s,z.CVa0Ze
设置新密码
ALTER USER 'root'@'localhost' IDENTIFIED BY 'root'; 第二个root位置输入新的密码
完成后重启 systemctl restart mysqld.service
授权,不授权外界是不能访问的,也就是不能通过远程访问数据库
mysql -uroot -proot登录后
关闭防火墙 systemctl stop firewalld
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root';授权外界访问,当然也可以建立普通用户后,设置对外访问的用户密码
修改字符集
1、修改配置文件
vim /etc/my.cnf
在最后加上中文字符集配置
character_set_server=utf8
2、重新启动mysql
3、已生成的库表字符集如何变更
修改数据库的字符集
mysql> alter database mydb character set 'utf8';
修改数据表的字符集
mysql> alter table mytbl convert to character set 'utf8';