目录
3.9.1执行如果出现错误,可能缺少这个依赖:yum install libaio
3.10、修改Mysql配置文件,并将配置文件放到/etc/init.d/目录下面
3.10.1将当前配置文件加入到启动/etc/init.d/mysqld
3.11、加入开启自启动,启动mysql。(这个用不用都行)
14.1 如果不只是在 /usr/local/mysql路径下面可能会报错,那么执行下面操作,软连接
1、常用命令总结
1.rpm卸载: rpm -e --nodeps mysql-community-common-8.0.19-1.el7.x86_64
rpm查找: rpm -qa | grep mariadb
2.yum卸载:yum remove xx
3.服务重启操作命令:systemctl restart mysqld
查看状态: systemctl status mysqld
centos6.5mysql的服务操作命令:service mysql start/stop
4.关闭防火墙 :systemctl stop firewalld.service
开机禁止启动防火墙:systemctl disable firewalld.service
2、rpm下载安装(最快捷方式)
2.1、卸载mariadb
1、查找命令: rpm -qa | grep mariadb
2、查找几个就卸载几个,下载命令如下: rpm -e --nodeps mariadb-libs-5.5.64-1.el7.x86_64
3、卸载完成之后,vim /etc/my.cnf 应该就没了。这个时候就代表卸载完成
2.2、安装依赖
具体根据实际情况,缺啥安装啥,这个也没细总结过
yum install perl -y
2.3、下载rpm文件
2.3.1下载地址
https://dev.mysql.com/downloads/mysql/
2.3.2下载整合版Bundle
2.3.3下载四个文件
下载地址是:
https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-community-server-5.7.30-1.el7.x86_64.rpm
https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-community-server-5.7.30-1.el7.x86_64.rpm
https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-community-common-5.7.30-1.el7.x86_64.rpm
https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-community-libs-5.7.30-1.el7.x86_64.rpm
(选择对应的版本)按照顺序来
(mysql-community-common-5.7.30-1.el7.x86_64.rpm)
(mysql-community-libs-5.7.30-1.el7.x86_64.rpm)
(mysql-community-server-5.7.30-1.el7.x86_64.rpm)
(mysql-community-client-5.7.30-1.el7.x86_64.rpm)
2.4、执行命令安装
如果存在冲突或者缺少依赖:
如卸载命令: rpm -e --nodeps mysql-community-common-8.0.19-1.el7.x86_64
如安装命令:yum install gcc -y
依次安装即可,要注意顺序
sudo rpm -ivh mysql-community-common-5.7.30-1.el7.x86_64.rpm
sudo rpm -ivh mysql-community-libs-5.7.30-1.el7.x86_64.rpm
sudo rpm -ivh mysql-community-client-5.7.30-1.el7.x86_64.rpm
sudo rpm -ivh mysql-community-server-5.7.30-1.el7.x86_64.rpm
到这里默认就安装结束,同时已经启动mysql的服务
2.5、安装目录如下
数据库目录:/var/lib/mysql/
命令配置:/usr/share/mysql (mysql.server命令及配置文件)
相关命令:/usr/bin (mysqladmin mysqldump等命令)
启动脚本:/etc/rc.d/init.d/ (启动脚本文件mysql的目录)
系统配置:/etc/my.conf
2.6、查看mysql运行状态,并重启
systemctl status mysqld
systemctl restart mysqld
2.7、重置密码
1:vim /etc/my.cnf
2:在最后加上: skip-grant-tables
3:重启mysql服务: systemctl restart mysqld
4: mysql -u root-p 不需要输入密码直接enter即可
5:设置root账号的密码:
设置密码:update mysql.user set authentication_string=password('123456') where user='root' ;
刷新:FLUSH PRIVILEGES;
6:退出mysql:将之前加入的跳过密码验证删掉
命令:vim /etc/my.cnf
把skip-grant-tables去掉
7: 重新登录数据库
执行命令出现不能操作情况:show databases;
修改密码即可:alter user 'root'@'localhost' identified by 'Root123456xxx';
8:外部不能连接问题
use mysql ;
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'Root123456xxx' WITH GRANT OPTION;
flush privileges;刷新
9 : 安装完成了
3、tar安装
卸载:mariadb
1、 rpm -qa | grep mariadb
2、rpm -e --nodeps mariadb-libs-5.5.64-1.el7.x86_64
3、卸载完成之后,vim /etc/my.cnf 应该就没了
3.1、下载安装包
地址: https://dev.mysql.com/downloads/mysql/
选择:(mysql-5.7.29-el7-x86_64.tar.gz)
3.2、上传到服务器
位置是:/usr/local/ 目录下
3.3、解压到当前文件夹/usr/local/
如果是
tar文件:tar -xvf mysql-5.7.29-linux-glibc2.12-x86_64.tar
如果是
tar.gz解压 :tar -zxvf mysql-5.7.29-linux-glibc2.12-x86_64.tar.gz
改名字:mv /usr/local/mysql-5.7.29-linux-glibc2.12-x86_64
mysql
3.4、创建data路径
mkdir /usr/local/mysql/data
3.5、创建mysql用户组
groupadd mysql
useradd -r -g mysql mysql
3.6、授权用户组
chown -R mysql:mysql /usr/local/mysql
chown -R mysql:mysql /usr/local/mysql/data
3.7、初始化脚本,5.7中 这个过时了(这里不采用)
/usr/local/mysql/bin/mysql_install_db --user=mysql
[root@ip-100 bin]# /usr/local/mysql/bin/mysql_install_db --user=mysql
2020-01-16 01:23:59 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
2020-01-16 01:23:59 [ERROR] The data directory needs to be specified.
3.8、更改mysql安装文件夹mysql/的权限
chmod -R 755 /usr/local/mysql/
3.9、初始化mysql
3.9.1执行如果出现错误,可能缺少这个依赖:yum install libaio
/usr/local/mysql/bin/mysqld --user=mysql --basedir=
/usr/local/mysql --datadir=
/usr/local/mysql/data --initialize
下面是输出内容,注意最后一行的初始化密码,
2020-01-15T17:31:36.283878Z 1 [Note] A temporary password is generated for root@localhost: spPwujtd1z%X
2020-01-15T17:31:36.283878Z 1 [Note] A temporary password is generated for root@localhost: spPwujtd1z%X
[root@ip-100 mysql]# /usr/local/mysql/bin/mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --initialize
2020-01-15T17:31:33.818233Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2020-01-15T17:31:34.417755Z 0 [Warning] InnoDB: New log files created, LSN=45790
2020-01-15T17:31:34.510250Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2020-01-15T17:31:34.759518Z 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: e0788195-37bc-11ea-a2a6-000c29cf0c82.
2020-01-15T17:31:34.765729Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2020-01-15T17:31:35.831655Z 0 [Warning] CA certificate ca.pem is self signed.
2020-01-15T17:31:36.283878Z 1 [Note] A temporary password is generated for root@localhost: spPwujtd1z%X
3.10、修改Mysql配置文件,并将配置文件放到/etc/init.d/目录下面
vim /usr/local/mysql/support-files/mysql.server
# Set some defaults
mysqld_pid_file_path=
if test -z "$basedir"
then
basedir=/usr/local/mysql
bindir=/usr/local/mysql/bin
if test -z "$datadir"
then
datadir=/usr/local/mysql/data
fi
sbindir=/usr/local/mysql/bin
libexecdir=/usr/local/mysql/bin
else
bindir="$basedir/bin"
if test -z "$datadir"
then
datadir="$basedir/data"
fi
sbindir="$basedir/sbin"
libexecdir="$basedir/libexec"
fi
3.10.1将当前配置文件加入到启动/etc/init.d/mysqld
(ln -s /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld 也可以)
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod 755 /etc/init.d/mysqld
3.11、加入开启自启动,启动mysql。(这个用不用都行)
systemctl enable mysqld
3.12、添加my.cnf
vi /etc/my.cnf
原先内容:(可能不存在原先的内容)
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-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=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
覆盖的内容是:(如果没有卸载mariadb,加上这句 : !includedir /etc/my.cnf.d
)
[root@ip-100 mysql]# cat /etc/my.cnf
[client]
no-beep
socket =
/usr/local/mysql/mysql.sock
# pipe
# socket=0.0
port=3306
[mysql]
default-character-set=utf8
[mysqld]
basedir=
/usr/local/mysql
datadir
=/usr/local/mysql/data
port=3306
pid-file=
/usr/local/mysql/mysqld.pid
#skip-grant-tables
skip-name-resolve
socket =
/usr/local/mysql/mysql.sock
character-set-server=utf8
default-storage-engine=INNODB
explicit_defaults_for_timestamp = true
# Server Id.
server-id=1
max_connections=2000
query_cache_size=0
table_open_cache=2000
tmp_table_size=246M
thread_cache_size=300
#限定用于每个数据库线程的栈大小。默认设置足以满足大多数应用
thread_stack = 192k
key_buffer_size=512M
read_buffer_size=4M
read_rnd_buffer_size=32M
innodb_data_home_dir =
/usr/local/mysql/data
innodb_flush_log_at_trx_commit=0
innodb_log_buffer_size=16M
innodb_buffer_pool_size=256M
innodb_log_file_size=128M
innodb_thread_concurrency=128
innodb_autoextend_increment=1000
innodb_buffer_pool_instances=8
innodb_concurrency_tickets=5000
innodb_old_blocks_time=1000
innodb_open_files=300
innodb_stats_on_metadata=0
innodb_file_per_table=1
innodb_checksum_algorithm=0
back_log=80
flush_time=0
join_buffer_size=128M
max_allowed_packet=1024M
max_connect_errors=2000
open_files_limit=4161
query_cache_type=0
sort_buffer_size=32M
table_definition_cache=1400
binlog_row_event_max_size=8K
sync_master_info=10000
sync_relay_log=10000
sync_relay_log_info=10000
#批量插入数据缓存大小,可以有效提高插入效率,默认为8M
bulk_insert_buffer_size = 64M
interactive_timeout = 120
wait_timeout = 120
log-bin-trust-function-creators=1
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
# include all files from the config directory
!includedir /etc/my.cnf.d
3.13、mysql添加到环境变量中
vim ~/.bash_profile
PATH=$PATH:$HOME/bin:/usr/local/mysql/bin/
source ~/.bash_profile
3.14、启动mysql服务
/etc/init.d/mysqld start
#或者: systemctl restart mysqld
14.1 如果不只是在 /usr/local/mysql路径下面可能会报错,那么执行下面操作,软连接
执行:
ln -s /sofware/mysql/bin/mysqld /usr/local/mysql/mysqld
下面是网上的报错内容:
Starting MySQL.Logging to '/data/mysql/SZY.err'.
2018-07-02T10:09:03.779928Z mysqld_safe The file /usr/local/mysql/bin/mysqld
does not exist or is not executable. Please cd to the mysql installation
directory and restart this script from there as follows:
./bin/mysqld_safe&
See http://dev.mysql.com/doc/mysql/en/mysqld-safe.html for more information
ERROR! The server quit without updating PID file (/software/mysql/mysqld.pid).
因为新版本的mysql安全启动安装包只认/usr/local/mysql这个路径。解决办法:
方法1、建立软连接
cd /usr/local/mysql
ln -s /sofware/mysql/bin/myslqd /usr/local/mysql/mysqld
方法2、修改mysqld_safe文件(有强迫症的同学建议这种,我用的这种)
vim /software/mysql/bin/mysqld_safe
#将所有的/usr/local/mysql改为/software/mysql
保存退出。(可以将这个文件拷出来再修改然后替换)
3.15、登录
15.1: /usr/local/mysql/bin/mysql -u root –p
输入的密码是刚才初始化的时候生成的密码
15.2:修改mysql的登录密码,在mysql的控制台直接执行即可
mysql> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
set password=password('root');
grant all privileges on *.* to root@'%' identified by 'root';
flush privileges;
3.16、修改密码命令:
alter user 'root'@'localhost' identified by 'root.?';
flush privileges;
到此安装完成。