Mysql官网https://dev.mysql.com/downloads/mysql/选择自己想用的版本,此次用的5.5
1、Linux下若通过yum安装会默认安装的mariadb,先检查下本地是否安装了Mariadb
[root@server ~]# rpm -qa| grep -i mariadb
mariadb-libs-5.5.60-1.el7_5.x86_64
mariadb-5.5.60-1.el7_5.x86_64
通过rpm -e 或者yum remove的方式卸载
[root@server ~]# rpm -e `rpm -qa| grep -i mariadb`
[root@server ~]# rpm -qa| grep -i mariadb
2、Mysql下载安装
官网下载很慢,可以去腾讯镜像站。https://mirrors.cloud.tencent.com/mysql/downloads/MySQL-5.5/
[root@server ~]# wget https://mirrors.cloud.tencent.com/mysql/downloads/MySQL-5.5/MySQL-5.5.61-2.el7.x86_64.rpm-bundle.tar
[root@server ~]# ll
总用量 190564
-rw-------. 1 root root 1266 7月 5 00:34 anaconda-ks.cfg
-rw-r--r-- 1 root root 195133440 6月 16 2018 MySQL-5.5.61-2.el7.x86_64.rpm-bundle.tar
[root@server ~]# tar xvf MySQL-5.5.61-2.el7.x86_64.rpm-bundle.tar #解压
mysql-community-test-5.5.61-2.el7.x86_64.rpm
mysql-community-embedded-5.5.61-2.el7.x86_64.rpm
mysql-community-embedded-devel-5.5.61-2.el7.x86_64.rpm
mysql-community-devel-5.5.61-2.el7.x86_64.rpm
mysql-community-minimal-debuginfo-5.5.61-2.el7.x86_64.rpm
mysql-community-server-minimal-5.5.61-2.el7.x86_64.rpm
mysql-community-common-5.5.61-2.el7.x86_64.rpm
mysql-community-bench-5.5.61-2.el7.x86_64.rpm
mysql-community-client-5.5.61-2.el7.x86_64.rpm
mysql-community-libs-5.5.61-2.el7.x86_64.rpm
mysql-community-server-5.5.61-2.el7.x86_64.rpm
[root@server ~]# yum install *.rpm
[root@server ~]# systemctl start mysqld
[root@server ~]# netstat -antup | grep mysqld
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 4975/mysqld
3、设置mysql密码
[root@server ~]# mysql #第一次登陆无需密码
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.5.61 MySQL Community Server (GPL)
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
=============================通过mysql_secure_installation==================
[root@server ~]# 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] #设置root密码
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!
By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them. This is intended only for testing, 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] n #是否拒绝root远程登陆
... skipping.
By default, MySQL comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] y #是否移除test数据库
- Dropping test database...
... Success!
- 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!
Cleaning up...
All done! If you've completed all of the above steps, your MySQL
installation should now be secure.
Thanks for using MySQL!
[root@server ~]# mysql -uroot -p[密码] #进行登陆
=======================通过mysqladmin设置密码=============================
[root@server ~]# mysqladmin -uroot password [密码]
=======================通过授权方式===========================
[root@server ~]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.5.61 MySQL Community Server (GPL)
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> grant all privileges on *.* to 'root'@'localhost' identified by '000000';
Query OK, 0 rows affected (0.00 sec)
mysql> grant all privileges on *.* to 'root'@'%' identified by '000000';
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)