coentos mysql 重启_[CoentOS] MySQL删除和安装

删除 MySQL

yum remove mysql mysql-server mysql-libs mysql-server;

find / -name mysql 将找到的相关东西delete掉(rm -rf /var/lib/mysql)rpm -qa|grep mysql(查询出来的东东yum remove掉)rm/etc/my.cnf

查看是否还有mysql软件:

rpm -qa|grep mysql

如果存在的话,继续删除即可。

[root@localhost opt]#rpm -qa | grep -i mysql

MySQL-server-5.6.17-1.el6.i686

MySQL-client-5.6.17-1.el6.i686

卸载mysql

[root@localhost local]# rpm -e MySQL-server-5.6.17-1.el6.i686

[root@localhost local]# rpm -e MySQL-client-5.6.17-1.el6.i686

删除mysql服务

[root@localhost local]#chkconfig --list | grep -i mysql

[root@localhost local]# chkconfig --del mysql

删除分散mysql文件夹

[root@localhost local]# whereis mysql 或者 find / -name mysql

mysql: /usr/lib/mysql /usr/share/mysql

清空相关mysql的所有目录以及文件

rm -rf /usr/lib/mysql

rm -rf /usr/share/mysql

rm -rf /usr/my.cnf

通过以上几步,mysql应该已经完全卸载干净了.

安装MySQL

1、配置YUM源

#下载mysql源安装包wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm#安装mysql源yum localinstall mysql57-community-release-el7-8.noarch.rpm

2. 检查mysql源是否安装成功

shell> yum repolist enabled | grep "mysql.*-community.*"

3. 安装服务

yum install mysql-server

yum install mysql-devel

4. 打开服务

systemctl start mysqld //打开MySQL服务

5. 检测服务状态(可省略)

systemctl status mysqld //可以查看MySQL服务是否正常打开(可省略)

5ab1231f13e70da8d90f225100a5e553.png

6. 查看安装时自动设置的随机密码

grep "temporary password" /var/log/mysqld.log

CentOS系统用yum安装MySQL的朋友,请使用 grep "temporary password" /var/log/mysqld.log 命令,返回结果最后引号后面的字符串就是root的默认密码。

bbdc1853f77d563168c907897582d18f.png

如图可以看出,我这次安装的MySQL的初始密码是【S+NwpxfZt0o;】

7. 相关配置

#######安装成功后,将其加入开机启动

[root@typecodes ~]# systemctl enable mysqld

#######启动mysql服务进程

[root@typecodes ~]# systemctl start mysqld

#######配置mysql(设置密码等)

[root@typecodes ~]# mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL

SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!In order to log into MySQL to secure it, we'll need the current

password for the root user. If you've just installed MySQL, and

you haven't set the root password yet, the password will be blank,

so you should just press enter here.

Enter current password for root (enter for none):

OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MySQL

root user without the proper authorisation.

Set root password? [Y/n] y [设置root用户密码]

New password:

Re-enter newpassword:

Password updated successfully!Reloading privilege tables..

... Success!Bydefault, a MySQL installation has an anonymous user, allowing anyone

to log into MySQL without having to have a user account createdforthem. This is intended onlyfortesting, and to make the installation

go a bit smoother. You should remove them before moving into a

production environment.

Remove anonymous users? [Y/n] y [删除匿名用户]

... Success!Normally, root should only be allowed to connect from'localhost'. This

ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] y [禁止root远程登录]

... Success!Bydefault, MySQL comes with a database named 'test'that anyone can

access. This is also intended onlyfortesting, and should be removed

before moving into a production environment.

Remove test database and access to it? [Y/n] y [删除test数据库]

-Dropping test database...

ERROR1008 (HY000) at line 1: Can't drop database 'test'; database doesn't exist

... Failed!Not critical, keep moving...-Removing privileges on test database...

... Success!Reloading the privilege tables will ensure that all changes made so far

will take effect immediately.

Reload privilege tables now? [Y/n] y [刷新权限]

... Success!All done! If you've completed all of the above steps, your MySQL

installation should now be secure.

Thanks for using MySQL!

Cleaning up...

8. 可能有效的MySQL配置优化

在原始配置文件  /etc/my.cnf 基础上,在 [mysqld] 节内增加配置参数。实际应用中,请按硬件及负载酌情修改。

#add by feng 120418 --------------------------#skip-locking

skip-name-resolve

skip-external-locking

key_buffer_size=256M

#table_cache= 3072table_open_cache= 3072read_buffer_size=2M

read_rnd_buffer_size=2M

sort_buffer_size=2M

myisam_sort_buffer_size=256M

thread_cache_size= 8query_cache_size=512M

query_cache_limit=5M

tmp_table_size=1024M

max_heap_table_size=3000M

max_allowed_packet=16M

innodb_buffer_pool_size=512M

innodb_log_file_size=512M

innodb_additional_mem_pool_size=512M

innodb_log_buffer_size=64M

max_connections=2000max_user_connections=800join_buffer_size=8M

open_files_limit= 65535#tmpdir=/dev/shm

max_connect_errors=1000#add by feng120418 end ---------------------

9. 其它命令

1:安装完成路径:1、数据库目录/var/lib/mysql/

2、配置文件/usr/share/mysql(mysql.server命令及配置文件)

3、启动脚本/etc/rc.d/init.d/(启动脚本文件mysql的目录)4、相关命令/usr/bin(mysqladmin mysqldump等命令)

注:1~3安装server安装后存在,4mysqladmin mysqldump在client安装后存在

b、停止

service mysqld stop

c、重启

service mysqld restart

y

d, 启动

service mysqld start

e, 强行关闭MySQL

killall mysqld

f, 查看是否启动成功,进程mysql启动,网络端口3306开启为ok.

ps aux|grep mysql

g, 登录

mysql-u root -p

f, 查看MySQL中all user

SELECT DISTINCT CONCAT('User: ''',user,'''@''',host,''';') AS query FROM mysql.user;

h, 允许远程机器用root用户连接MySQL服务器数据库

GRANT ALL PRIVILEGES ON*.* TO 'root'@'%' IDENTIFIED BY 'youpassword'WITH GRANT OPTION;

FLUSH PRIVILEGES;

UPDATE USER SET HOST= '%' WHERE HOST='127.0.0.1' AND USER='root'

参考文章:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值