CentOS下MySQL安装后配置和设置

来源:互联网 发布:单片机编程培训 编辑:程序博客网 时间:2024/05/16 12:06

CentOS下MySQL安装后配置和设置:

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安装后存在

查看数据库版本:

mysql> select version();+-----------+| version() |+-----------+| 5.6.27    |+-----------+1 row in set (0.00 sec)

2:启动mysql:

[root@localhost install-files]# service mysqld start  Starting MySQL.. SUCCESS!  

停止mysql:

[root@localhost init.d]# service mysqld stopShutting down MySQL.. SUCCESS! 

重启mysql:

[root@localhost init.d]# service mysqld restartShutting down MySQL.. SUCCESS! Starting MySQL. SUCCESS! 

注:启动脚本名称修改:

[root@localhost ~]# cd /etc/rc.d/init.d/[root@localhost init.d]# lsfunctions  mysql  netconsole  network  README[root@localhost init.d]# mv mysql mysqld[root@localhost init.d]# lsfunctions  mysqld  netconsole  network  README

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

[root@Tony_ts_tian ~]# ps aux | grep mysqlroot     28992  0.0  0.1  11340  1384 pts/0    S    15:02   0:00 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --pid-file=/var/lib/mysql/Tony_ts_tian.pidmysql    29095  0.0 44.7 1014444 455420 pts/0  Sl   15:02   0:04 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --log-error=/var/lib/mysql/Tony_ts_tian.err --pid-file=/var/lib/mysql/Tony_ts_tian.pidroot     29165  0.0  0.0 103252   836 pts/0    S+   17:04   0:00 grep mysql[root@Tony_ts_tian ~]# netstat -ntlActive Internet connections (only servers)Proto Recv-Q Send-Q Local Address               Foreign Address             State      tcp        0      0 0.0.0.0:6379                0.0.0.0:*                   LISTEN      tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      tcp        0      0 0.0.0.0:8081                0.0.0.0:*                   LISTEN      tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      tcp        0      0 127.0.0.1:8006              0.0.0.0:*                   LISTEN      tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      tcp        0      0 0.0.0.0:3690                0.0.0.0:*                   LISTEN      tcp        0      0 0.0.0.0:8010                0.0.0.0:*                   LISTEN 

4:设置MySQL开机启动:

查看开机启动项:

[root@Tony_ts_tian ~]# chkconfig 

查看是否有MySQL开机启动:

[root@Tony_ts_tian ~]# chkconfig --list | grep mysql*

设置开机启动:

[root@Tony_ts_tian ~]# chkconfig --add mysqld

或开启和关闭:chkconfig mysqld on / chkconfig mysqld off
设置效果:

[root@Tony_ts_tian ~]# chkconfig --list | grep mysql*mysqld         0:off1:off2:on3:on4:on5:on6:off

以上表示设置成功。

注:rpm安装后初始密码在/root/.mysql_secret

5:创建管理员root密码:

注:第一次安装完mysql后,不需要输入密码,直接mysql命令,就可以登陆!5.1.

[root@Tony_ts_tian bin]# mysql -V
mysql  Ver 14.14 Distrib 5.1.73, for redhat-linux-gnu (x86_64) using readline 5.1

[root@Tony_ts_tian bin]# pwd/usr/bin[root@Tony_ts_tian bin]# mysqladmin -u root password 'kaka123'

6:登录:

mysql -u root -p

Enter password:  不回显,输入正确密码enter即可登陆。

(7:忘记密码):第5步可能也会出错:第9步也会出错:

解决:MySQL配置和设置问题小结

即可,登录,修改密码。

注:也可使用:/etc/mysql/debian.cnf文件中[client]下配置的密码。

8:查看MySQL中all user:

查看数据库中所有用户:

mysql> SELECT DISTINCT CONCAT('User: ''',user,'''@''',host,''';') AS query FROM mysql.user;+--------------------------------+| query                          |+--------------------------------+| User: 'root'@'127.0.0.1';      || User: 'root'@'::1';            || User: 'root'@'localhost';      || User: 'root'@'tony\_ts\_tian'; |+--------------------------------+4 rows in set (0.00 sec)

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

a:查看表结构,插入一列,用户名User=root,Host='%',表示不限制ip为允许所有ip访问,密码

mysql> DESC user;

发现mysql数据库下user表中,Host和User为主键列。(SQL来自备份user表),设置登录的Host为所有:

INSERT  INTO `user`(`Host`,`User`,`Password`,`Select_priv`,`Insert_priv`,`Update_priv`,`Delete_priv`,`Create_priv`,`Drop_priv`,`Reload_priv`,`Shutdown_priv`,`Process_priv`,`File_priv`,`Grant_priv`,`References_priv`,`Index_priv`,`Alter_priv`,`Show_db_priv`,`Super_priv`,`Create_tmp_table_priv`,`Lock_tables_priv`,`Execute_priv`,`Repl_slave_priv`,`Repl_client_priv`,`Create_view_priv`,`Show_view_priv`,`Create_routine_priv`,`Alter_routine_priv`,`Create_user_priv`,`Event_priv`,`Trigger_priv`,`Create_tablespace_priv`,`ssl_type`,`ssl_cipher`,`x509_issuer`,`x509_subject`,`max_questions`,`max_updates`,`max_connections`,`max_user_connections`,`plugin`,`authentication_string`,`password_expired`) VALUES ('%','root','*6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0,0,'mysql_native_password','','N');

修改登录密码:

mysql> SELECT Host,User,Password FROM `user`;mysql> UPDATE `user` SET password='*71ABCA8B06D46066CEF8062A75256E66243D0FC8' WHERE Host='%' AND User='root';mysql> SELECT DISTINCT CONCAT('User: ''',user,'''@''',host,''';') AS query FROM mysql.user;+--------------------------------+| query                          |+--------------------------------+| User: 'root'@'%';              || User: 'root'@'127.0.0.1';      || User: 'root'@'::1';            || User: 'root'@'localhost';      || User: 'root'@'tony\_ts\_tian'; |+--------------------------------+5 rows in set (0.00 sec)

b:或者直接更新,重启:

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

a,b后,刷新MySQL的系统权限相关表:

mysql> flush privileges;

重启,就可以远程访问了:

[root@Tony_ts_tian bin]# service mysqld restartShutting down MySQL.... SUCCESS! Starting MySQL. SUCCESS! 

登陆mysql数据库:

[root@Tony_ts_tian ~]# mysql -u root -pEnter password: Welcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 149Server version: 5.6.27 MySQL Community Server (GPL)Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> 

 







0 0