若有便删除(linux系统自带的)
rpm -qa | grep mariadb rpm -e --nodeps mariadb-libs-5.5.68-1.el7.x86_64 #组合 rpm -qa | grep -i mariadb | xargs rpm -e --nodeps
若有便删除(linux系统自带的)
rpm -qa | grep mysql
cat /etc/group | grep mysql cat /etc/passwd |grep mysql
若存在,则删除原mysql用户
userdel -r mysql
会删除其对应的组和用户
创建mysql组和mysql用户
groupadd mysql useradd -r -g mysql mysql
上传安装包到此目录下解压
tar -zxvf mysql-5.7.36-el7-x86_64.tar.gz
解压后修改目录名称为mysql
mv -f mysql-5.7.36-el7-x86_64 mysql chown -R mysql:mysql /usr/local/mysql chmod -R 755 mysql/
然后在mysql目录下创建data文件夹
cd mysql/ mkdir data chown -R mysql:mysql /usr/local/mysql/data chmod -R 755 data/
vim /etc/my.cnf
[mysqld] server-id=1 basedir=/usr/local/mysql datadir=/usr/local/mysql/data socket=/tmp/mysql.sock user=mysql port = 3306 lower_case_table_names=1 max_allowed_packet=400M log_bin_trust_function_creators=1 max_connections=1000 sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION' innodb_buffer_pool_size=1G innodb_log_file_size=256M innodb_flush_log_at_trx_commit=1 innodb_flush_method=O_DIRECT innodb_autoinc_lock_mode=2 innodb_flush_log_at_trx_commit=0 #binlog expire_logs_days=7 log-bin=mysql-bin binlog-format=ROW #指定默认引擎 disabled_storage_engines=MyISAM,BLACKHOLE,FEDERATED,CSV,ARCHIVE default_storage_engine=innodb symbolic-links=0 init_connect='SET collation_connection = utf8_unicode_ci' init_connect='SET NAMES utf8' character-set-server=utf8 collation-server=utf8_unicode_ci skip-character-set-client-handshake [mysql_safe] log-error=/var/log/mysqld.log pid-file=/tmp/mysqld/mysqld.pid [client] default-character-set=utf8 [mysql] default-character-set=utf8
设置用户组及用户,授权(这些文件对应的路径在my.cnf文件配置中体现)
cd /tmp touch mysql.sock chown mysql:mysql mysql.sock chmod 755 mysql.sock
创建文件 /tmp/mysqld/mysqld.pid
mkdir mysqld cd mysqld touch mysqld.pid cd ../ chown -R mysql:mysql mysqld cd mysqld chmod 755 mysqld.pid
创建记录错误日志文件/var/log/mysqld.log
touch /var/log/mysqld.log chown -R mysql:mysql /var/log/mysqld.log
进入bin目录
cd /usr/local/mysql/bin/
初始化数据库
./mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
(basedir、datadir目录和my.cnf保持一致)
执行完
在日志里记住初始密码:oFl2CiKd,4Tx
/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf --user=mysql &
nohup /usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf --user=mysql >> /usr/local/mysql/bin/mysql.log 2>&1 &
查看mysql进程
ps -ef | grep mysqld
判断是否启动
进入bin目录
cd /usr/local/mysql/bin/ ./mysql -u root -p
输入获得的默认密码,即可进入mysql命令客户端
#修改root用户登陆密码 set password = password('123456'); use mysql; #修改使root用户具有远程登陆的权限,不需要可不设置 update user set user.Host='%' where user.User='root'; #刷新权限 flush privileges;
#给予所有权限的创建 grant all on *.* TO 'wxhntmy'@"%" identified by "123456"; #刷新权限 flush privileges; #退出登陆 quit;
创建配置文件
touch /usr/lib/systemd/system/mysql.service vim /usr/lib/systemd/system/mysql.service
[Unit] Description=MySQL Server Documentation=man:mysqld(8) Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html After=network.target After=syslog.target [Install] WantedBy=multi-user.target [Service] User=mysql Group=mysql ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf LimitNOFILE = 5000 #Restart=on-failure #RestartPreventExitStatus=1 #PrivateTmp=false
通过 systemctl 来启动 mysql
systemctl status mysql systemctl start mysql systemctl stop mysql systemctl restart mysql ps -ef | grep mysql
通过 systemctl 来设置 mysql 开机启动
systemctl enable mysql
查看 centos7 防火墙状态
systemctl status firewalld
firewall-cmd --zone=public --add-port=3306/tcp --permanent
firewall-cmd --reload
firewall-cmd --zone=public --query-port=3306/tcp
vim ~/.bash_profile
export PATH=$PATH:/usr/local/mysql/bin
执行下面的命令是修改的内容立即生效
source ~/.bash_profile