1、新创建的服务器,需要检测系统是否自带安装mysql
# yum list installed | grep mysql
2、如果发现有系统自带mysql,请卸载
# yum -y remove mysql-libs.x86_64
3、下载mysql yum源
# wget http://repo.mysql.com/mysql-community-release-el6-5.noarch.rpm
4、配置MySQL的安装源
# rpm -ivh mysql-community-release-el6-5.noarch.rpm
5、安装mysql 服务器命令
# yum install mysql-community-server
6、安装成功后启动
# service mysqld start
7、由于mysql刚刚安装完的时候,mysql的root用户的密码默认是空的,所以我们需要及时用mysql的root用户登录(第一次回车键,不用输入密码),并修改密码
# mysql # show databases; +--------------------+ | Database | +--------------------+ | information_schema | | hive | | mysql | | performance_schema | +--------------------+ # use mysql; # show tables; +---------------------------+ | Tables_in_mysql | +---------------------------+ | columns_priv | | db | | event | | func | | general_log | | help_category | | help_keyword | | help_relation | | help_topic | | innodb_index_stats | | innodb_table_stats | | ndb_binlog_index | | plugin | | proc | | procs_priv | | proxies_priv | | servers | | slave_master_info | | slave_relay_log_info | | slave_worker_info | | slow_log | | tables_priv | | time_zone | | time_zone_leap_second | | time_zone_name | | time_zone_transition | | time_zone_transition_type | | user | +---------------------------+ # select host,user from user; +-----------+------+ | host | user | +-----------+------+ | 127.0.0.1 | root | | ::1 | root | | localhost | | | slave1 | | | slave1 | root | +-----------+------+ # grant all privileges on *.* to 'root'@'%' identified by 'root' with grant option; # select host,user from user; +-----------+------+ | host | user | +-----------+------+ | % | root | | 127.0.0.1 | root | | ::1 | root | | localhost | | | slave1 | | | slave1 | root | +-----------+------+ # delete from user where host != '%'; # select host,user from user; +------+------+ | host | user | +------+------+ | % | root | +------+------+ # flush privileges; # quit ; # service mysqld restart ; # mysql -uroot -proot; # show databases; +--------------------+ | Database | +--------------------+ | information_schema | | hive | | mysql | | performance_schema | +--------------------+ 4 rows in set (0.00 sec)
8、查看mysql是否自启动,并且设置开启自启动命令
# chkconfig --list | grep mysqld # chkconfig mysqld on
9、mysql安全设置
# mysql_secure_installation
Mysql5.7数据库初始密码查看及修改
自Mysql5.7初始密码不再默认为空!!!
1.查看初始密码:
- [root@master]# grep 'temporary password' /var/log/mysqld.log
- 2017-03-12T12:25:43.090102Z 1 [Note] A temporary password is generated for root@localhost: h8&%pgp/+BB2
2.登录及修改密码:
- [root@master]# mysql -uroot -p
- Enter password:
- Welcome to the MySQL monitor. Commands end with ; or \g.
- Your MySQL connection id is 3
- Server version: 5.7.17
-
- Copyright (c) 2000, 2016, 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> show databases;
- ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
3.修改密码:
- mysql> alter user root@localhost identified by 'Mysql123#';
- Query OK, 0 rows affected (0.00 sec)

本文详细介绍了在服务器上安装和配置MySQL数据库的过程,包括检查系统预装状态、下载及配置YUM源、安装服务器、启动服务、设置root用户密码、自启动设置及安全配置等关键步骤。
869

被折叠的 条评论
为什么被折叠?



