我的编程空间,编程开发者的网络收藏夹
学习永远不晚

LINUX下配置MYSQL

短信预约 -IT技能 免费直播动态提醒
省份

北京

  • 北京
  • 上海
  • 天津
  • 重庆
  • 河北
  • 山东
  • 辽宁
  • 黑龙江
  • 吉林
  • 甘肃
  • 青海
  • 河南
  • 江苏
  • 湖北
  • 湖南
  • 江西
  • 浙江
  • 广东
  • 云南
  • 福建
  • 海南
  • 山西
  • 四川
  • 陕西
  • 贵州
  • 安徽
  • 广西
  • 内蒙
  • 西藏
  • 新疆
  • 宁夏
  • 兵团
手机号立即预约

请填写图片验证码后获取短信验证码

看不清楚,换张图片

免费获取短信验证码

LINUX下配置MYSQL

初次学习在Linux下配置Mysql,首先查找版本,环境;部署后,启动Mysql,检验数据库是否运行正常

[@more@]--查看LINUX版本
[root@sd ~]# cat /etc/issue
Red Hat Enterprise Linux AS release 4 (Nahant)
Kernel r on an m
[root@sd ~]# cat /proc/version
Linux version 2.6.9-5.ELsmp (
bhcompile@decompose.build.redhat.com) (gcc version 3.4.3 20041212 (Red Hat 3.4.3-9.EL4)) #1 SMP Wed Jan 5 19:30:39 EST 2005
--Kernel
[root@sd ~]# uname -r
2.6.9-5.ELsmp
--查看CPU
[root@sd ~]# grep "model name" /proc/cpuinfo
model name : Intel(R) Xeon(R) CPU 5130 @ 2.00GHz
model name : Intel(R) Xeon(R) CPU 5130 @ 2.00GHz
model name : Intel(R) Xeon(R) CPU 5130 @ 2.00GHz
model name : Intel(R) Xeon(R) CPU 5130 @ 2.00GHz
--MEM
[root@sd ~]# free
total used free shared buffers cached
Mem: 4147280 1467312 2679968 0 105028 1141932
-/+ buffers/cache: 220352 3926928
Swap: 4192924 0 4192924
--信息
[root@sd ~]# cat /proc/cpuinfo
-------------------------
---检查linux软件管理包
[root@sd ~]# rpm -qa system-config-packages
system-config-packages-1.2.23-1
--显示mysql安装包
[root@sd ~]# rpm -q mysql
mysql-4.1.7-4.RHEL4.1
[root@sd ~]# rpm -q apache
package apache is not installed
[root@sd ~]# rpm -q php
php-4.3.9-3.1
[root@sd ~]# rpm -q perl
perl-5.8.5-12
--列出安装包的详细列表
[root@sd ~]# rpm -qa |grep php
php-gd-4.3.9-3.1
php-pear-4.3.9-3.1
php-xmlrpc-4.3.9-3.1
php-ldap-4.3.9-3.1
php-pgsql-4.3.9-3.1
php-devel-4.3.9-3.1
php-mbstring-4.3.9-3.1
php-domxml-4.3.9-3.1
php-ncurses-4.3.9-3.1
php-odbc-4.3.9-3.1
php-snmp-4.3.9-3.1
php-4.3.9-3.1
php-imap-4.3.9-3.1
[root@sd ~]# rpm -qa |grep mysql
mysql-devel-4.1.7-4.RHEL4.1
mysql-4.1.7-4.RHEL4.1
mysqlclient10-devel-3.23.58-4.RHEL4.1
mysqlclient10-3.23.58-4.RHEL4.1
freeradius-mysql-1.0.1-2.RHEL4
libdbi-dbd-mysql-0.6.5-10.RHEL4.1
[root@sd ~]# rpm -qa |grep apache
[root@sd ~]# rpm -ql mysql-4.1.7-4.RHEL4.1
/etc/ld.so.conf.d/mysql-i386.conf
/etc/init.d/mysqld
/etc/my.cnf
/usr/bin/msql2mysql
/usr/bin/mysql
/usr/bin/mysql_config
/usr/bin/mysql_find_rows
/usr/bin/mysql_tableinfo
/usr/bin/mysql_waitpid
/usr/bin/mysqlaccess
/usr/bin/mysqladmin
/usr/bin/mysqlbinlog
/usr/bin/mysqlcheck
/usr/bin/mysqldump
/usr/bin/mysqldumpslow
/usr/bin/mysqlimport
/usr/bin/mysqlsho
/usr/share/info/mysql.info.gz
/usr/share/man/man1/mysql.1.gz
/usr/share/man/man1/mysqlaccess.1.gz
/usr/share/man/man1/mysqladmin.1.gz
/usr/share/man/man1/mysqldump.1.gz
/usr/share/man/man1/mysqlshow.1.gz
/usr/share/mysql

-------------------------------------------------------------
--Starting mysqld daemon with databases from /etc/init.d/mysqld

[root@sd mysql]# /etc/init.d/mysqld
Usage: /etc/init.d/mysqld {start|stop|status|condrestart|restart}
[root@sd mysql]# /etc/init.d/mysqld start
[root@sd mysql]# /etc/init.d/mysqld status
mysqld (pid 18373) is running...
[root@sd mysql]# netstat -nat
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:22273 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:32770 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN

[root@sd mysql]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 4 to server version: 4.1.7

Type 'help;' or 'h' for help. Type 'c' to clear the buffer.
mysql>
察看mysql是否在自动启动列表中
/sbin/chkconfig --list
[root@sd opt]# mysqladmin -u -p shutdown
mysqladmin: shutdown failed; error: 'Access denied; you need the SHUTDOWN privilege for this operation'
[root@sd opt]# /etc/init.d/mysqld stop
Stopping MySQL: [ OK ]
Stopping MySQL: [ OK ]
[root@sd opt]# ls /var/lib/mysql
ibdata1 ib_logfile0 ib_logfile1 mysql test
[root@sd opt]# mv /var/lib/mysql /opt/mydata/
[root@sd opt]# ls /var/lib/ -alt

[root@sd opt]# ls /opt/mydata/mysql
ibdata1 ib_logfile0 ib_logfile1 mysql test
[root@sd opt]# cd /opt/mydata/mysql
[root@sd mysql]# ls
ibdata1 ib_logfile0 ib_logfile1 mysql test
[root@sd mysql]# cd mysql

[root@sd mysql]# /etc/init.d/mysqld start
Timeout error occurred trying to start MySQL Daemon.
Starting MySQL: [FAILED]
[root@sd mysql]# /etc/init.d/mysqld status
mysqld (pid 18776) is running...
[root@sd mysql]# mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
[root@sd mysql]# /etc/init.d/mysqld stop
Stopping MySQL: [ OK ]
[root@sd mysql]# ps -ef |grep mysql
root 18845 17994 0 16:27 pts/1 00:00:00 grep mysql
[root@sd mysql]# vi /etc/init.d/mysqld

#!/bin/bash
#
# mysqld This shell script takes care of starting and stopping
# the MySQL subsystem (mysqld).
#
# chkconfig: - 64 36
# description: MySQL database server.
# processname: mysqld
# config: /etc/my.cnf
# pidfile: /var/run/mysqld/mysqld.pid

# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network


prog="MySQL"
datadir="/var/lib/mysql"
#datadir="/opt/mydata/mysql"

Entering Ex mode. Type "visual" to go to Normal mode.
:wq
"/etc/rc.d/init.d/mysqld" 111L, 2497C written
[root@sd mysql]# vi /etc/my.cnf
[mysqld]
#datadir=/opt/mydata/mysql
datadir=/var/lib/mysql
#socket=/opt/mydata/mysql/mysql.sock
socket=/var/lib/mysql/mysql.sock
# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility package).
old_passwords=1
[mysql.server]
user=mysql
basedir=/var/lib
[mysqld_safe]
err-log=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

Entering Ex mode. Type "visual" to go to Normal mode.
:q
[root@sd mysql]# cd /opt/mydata
[root@sd mydata]# ls
mysql
[root@sd mydata]# mv mysql /var/lib/
[root@sd mydata]# ls /var/lib/mysql
ibdata1 ib_logfile0 ib_logfile1 mysql test
[root@sd mydata]# /etc/init.d/mysqld status
mysqld is stopped
[root@sd mydata]# /etc/init.d/mysqld start
Starting MySQL: [ OK ]
[root@sd mydata]# mysql
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 3 to server version: 4.1.7

Type 'help;' or 'h' for help. Type 'c' to clear the buffer.
mysql> h
For the complete MySQL Manualonline, visit:
http://www.mysql.com/documentation
For info on technical support from MySQL developers, visit:
http://www.mysql.com/support
For info on MySQL books, utilities, consultants, etc., visit:
http://www.mysql.com/portal
List of all MySQL commands:
Note that all text commands must be first on line and end with ';'
? (?) Synonym for `help'.
clear (c) Clear command.
connect (r) Reconnect to the server. Optional arguments are db and host.
delimiter (d) Set query delimiter.
edit (e) Edit command with $EDITOR.
ego (G) Send command to mysql server, display result vertically.
exit (q) Exit mysql. Same as quit.
go (g) Send command to mysql server.
help (h) Display this help.
nopager (n) Disable pager, print to stdout.
notee (t) Don't write into outfile.
pager (P) Set PAGER [to_pager]. Print the query results via PAGER.
print (p) Print current command.
prompt (R) Change your mysql prompt.
quit (q) Quit mysql.
rehash (#) Rebuild completion hash.
source (.) Execute a SQL script file. Takes a file name as an argument.
status (s) Get status information from the server.
system (!) Execute a system shell command.
tee (T) Set outfile [to_outfile]. Append everything into given outfile.
use (u) Use another database. Takes database name as argument.

For server side help, type 'help contents'
mysql> show databases;
+----------+
| Database |
+----------+
| mysql |
| test |
+----------+
2 rows in set (0.00 sec)

mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> show tables;
+---------------------------+
| Tables_in_mysql |
+---------------------------+
| columns_priv |
| db |
| func |
| help_category |
| help_keyword |
| help_relation |
| help_topic |
| host |
| tables_priv |
| time_zone |
| time_zone_leap_second |
| time_zone_name |
| time_zone_transition |
| time_zone_transition_type |
| user |
+---------------------------+
15 rows in set (0.00 sec)
mysql> describe db;
+-----------------------+---------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------------------+---------------+------+-----+---------+-------+
| Host | char(60) | | PRI | | |
| Db | char(64) | | PRI | | |
| User | char(16) | | PRI | | |
| Select_priv | enum('N','Y') | | | N | |
| Insert_priv | enum('N','Y') | | | N | |
| Update_priv | enum('N','Y') | | | N | |
| Delete_priv | enum('N','Y') | | | N | |
| Create_priv | enum('N','Y') | | | N | |
| Drop_priv | enum('N','Y') | | | N | |
| Grant_priv | enum('N','Y') | | | N | |
| References_priv | enum('N','Y') | | | N | |
| Index_priv | enum('N','Y') | | | N | |
| Alter_priv | enum('N','Y') | | | N | |
| Create_tmp_table_priv | enum('N','Y') | | | N | |
| Lock_tables_priv | enum('N','Y') | | | N | |
+-----------------------+---------------+------+-----+---------+-------+
15 rows in set (0.00 sec)

mysql> select * from db;
+------+---------+------+-------------+-------------+-------------+-------------+-------------+-----------+------------+-----------------+------------+------------+-----------------------+------------------+
| Host | Db | User | Select_priv | Insert_priv | Update_priv | Delete_priv | Create_priv | Drop_priv | Grant_priv | References_priv | Index_priv | Alter_priv | Create_tmp_table_priv | Lock_tables_priv |
+------+---------+------+-------------+-------------+-------------+-------------+-------------+-----------+------------+-----------------+------------+------------+-----------------------+------------------+
| % | test | | Y | Y | Y | Y | Y | Y | N | Y | Y | Y | Y | Y |
| % | test_% | | Y | Y | Y | Y | Y | Y | N | Y | Y | Y | Y | Y |
+------+---------+------+-------------+-------------+-------------+-------------+-------------+-----------+------------+-----------------+------------+------------+-----------------------+------------------+
2 rows in set (0.00 sec)

mysql> create database sdtest;
Query OK, 1 row affected (0.00 sec)
mysql> show databases;
+----------+
| Database |
+----------+
| mysql |
| sdtest |
| test |
+----------+
3 rows in set (0.00 sec)
mysql> show tables;
+---------------------------+
| Tables_in_mysql |
+---------------------------+
| columns_priv |
| db |
| func |
| help_category |
| help_keyword |
| help_relation |
| help_topic |
| host |
| tables_priv |
| time_zone |
| time_zone_leap_second |
| time_zone_name |
| time_zone_transition |
| time_zone_transition_type |
| user |
+---------------------------+
15 rows in set (0.00 sec)

mysql> use sdtest
Database changed
mysql> show tables;
Empty set (0.00 sec)

mysql> create table name( id int(3) auto_increment not null primary key,csny date,xm char(9),xy char(9));
Query OK, 0 rows affected (0.00 sec)

mysql> show tables;
+------------------+
| Tables_in_sdtest |
+------------------+
| name |
+------------------+
1 row in set (0.00 sec)

mysql> select * from name;
Empty set (0.00 sec)

mysql> describe name ;
+-------+---------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+---------+------+-----+---------+----------------+
| id | int(3) | | PRI | NULL | auto_increment |
| csny | date | YES | | NULL | |
| xm | char(9) | YES | | NULL | |
| xy | char(9) | YES | | NULL | |
+-------+---------+------+-----+---------+----------------+
4 rows in set (0.00 sec)

mysql> insert into name values('','1981-01-10','MM','SEXY');
Query OK, 1 row affected, 1 warning (0.00 sec)

mysql> select * from name;
+----+------------+------+------+
| id | csny | xm | xy |
+----+------------+------+------+
| 1 | 1981-01-10 | MM | SEXY |
+----+------------+------+------+
1 row in set (0.00 sec)
[root@sd mydata]# mysql
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 4 to server version: 4.1.7

Type 'help;' or 'h' for help. Type 'c' to clear the buffer.
mysql> use sdtest;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> insert into name values('','1981-03-30','GG','HANDSOME');
Query OK, 1 row affected, 1 warning (0.00 sec)

mysql> insert into name values('','1981-03-30','DY','SMITH');
Query OK, 1 row affected, 1 warning (0.00 sec)

mysql> select * from name;
+----+------------+------+----------+
| id | csny | xm | xy |
+----+------------+------+----------+
| 1 | 1981-01-10 | MM | SEXY |
| 2 | 1981-03-30 | GG | HANDSOME |
| 3 | 1981-03-30 | DY | SMITH |
+----+------------+------+----------+
3 rows in set (0.00 sec)

mysql> update name set xm='XX' where xm='DY';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0

mysql> select * from name;
+----+------------+------+----------+
| id | csny | xm | xy |
+----+------------+------+----------+
| 1 | 1981-01-10 | MM | SEXY |
| 2 | 1981-03-30 | GG | HANDSOME |
| 3 | 1981-03-30 | XX | SMITH |
+----+------------+------+----------+
3 rows in set (0.00 sec)

mysql> grant select ,insert,update,delete on *.* to hnzx_hq@"%" identified by "huangq";
Query OK, 0 rows affected (0.00 sec)

mysql> grant select ,update on sdtest.* to testman@localhost identified by "123";
Query OK, 0 rows affected (0.00 sec)

mysql> quit
Bye
[root@sd mydata]# mysql -u hnzx_hq -p huangq
Enter password:
ERROR 1045 (28000): Access denied for user
'hnzx_hq'@'localhost' (using password: YES)
[root@sd mydata]# mysql -u hnzx_hq -p
Enter password:
ERROR 1045 (28000): Access denied for user
'hnzx_hq'@'localhost' (using password: YES)
[root@sd mydata]# mysql -u hnzx_hq -p -h
Enter password:
ERROR 1045 (28000): Access denied for user
'hnzx_hq'@'sd.server.gov.com' (using password: YES)
[root@sd mydata]# mysqldump -u root -p --opt sdtest >back_sdtest
Enter password:
[root@sd mydata]# ls /var/lib/mysql
ibdata1 ib_logfile0 ib_logfile1 mysql mysql.sock sdtest test
[root@sd mydata]# cd sdtest
-bash: cd: sdtest: No such file or directory
[root@sd mydata]# cd /var/lib/mysql/sdtest
[root@sd sdtest]# ls
db.opt name.frm name.MYD name.MYI
[root@sd sdtest]# mysqldump -u root -p --opt sdtest > back_sdtest
Enter password:
[root@sd sdtest]# ls /var/lib/mysql
ibdata1 ib_logfile0 ib_logfile1 mysql mysql.sock sdtest test
[root@sd sdtest]# cd /var/lib/mysql/sdtest
[root@sd sdtest]# ls
back_sdtest db.opt name.frm name.MYD name.MYI
[root@sd sdtest]# mysql -u root -p ccc < back_sdtest
Enter password:
ERROR 1049 (42000): Unknown database 'ccc'
[root@sd sdtest]# mysql -u root -p cc < back_sdtest
Enter password:
ERROR 1049 (42000): Unknown database 'cc'
[root@sd sdtest]#

免责声明:

① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。

② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341

LINUX下配置MYSQL

下载Word文档到电脑,方便收藏和打印~

下载Word文档

猜你喜欢

Linux下MySQL安装配置 MySQL配置参数详解

一、下载编译安装 #cd /usr/local/src/ #wget http://mysql.byungsoo.net/Downloads/MySQL-5.1/mysql-5.1.38.tar.gz #tar –xzvf mysql-5.1.38.tar.g
Linux下MySQL安装配置 MySQL配置参数详解
2015-11-24

mysql 在 linux下的安装 和 配置

文章目录 1. linux 安装mysql1. 源码安装1.找到源码包2: 进行配置3:初始化数据目录官方说明 自用4:启动数据库5:写入环境变量 2:使用yum安装1. 直接配置mysql仓库 或者下载MySQL
2023-08-16

Linux下MySQL 8.0如何安装配置

这篇文章给大家分享的是有关Linux下MySQL 8.0如何安装配置的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。1、编译安装MySQL8.0版本信息#cat /etc/redhat-release CentOS
2023-06-15

Linux下查看MySQL的配置文件my.cnf位置

安装mysql后,系统中会有多个my.cnf文件。 查找系统中存在的所有my.cnf文件 使用 locate my.cnf 命令可以列出所有的my.cnf文件: > locate my.cnf/etc/my.cnf/usr/local/my
2023-08-16

LINUX下Android NDK下载并配置

下载 https://developer.android.google.cn/ndk/downloads/ https://developer.android.google.cn/ndk/downloads/older_releases 编
2022-06-06

Linux下如何配置Caddy

这篇文章主要为大家展示了“Linux下如何配置Caddy”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“Linux下如何配置Caddy”这篇文章吧。Caddy是一款快速,易用的生产型开源Web服务
2023-06-27

Linux下安装配置maven

一、安装以及配置maven 1.下载maven安装包 首先需要切换到自己需要安装的目录 我自己是把配置都放到了:/home/sunny 路径下 cd /home/sunny 下载maven安装包:wget https://archive.a
2023-08-19

Linux下如何配置VPS

这篇文章主要介绍了Linux下如何配置VPS,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。VPS又叫虚似专用服务器。它就相当于是一种技术,可以将一部服务器分割成多个虚似专享服
2023-06-27

Linux下如何配置MOC

这篇文章给大家分享的是有关Linux下如何配置MOC的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。Music On Console (MOC)是一款在Linux/Unix文字接口下的音乐播放程式。 MOC功能强大
2023-06-28

Linux下如何配置PPTP

这篇文章主要介绍了Linux下如何配置PPTP,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。PPTP(Point to Point Tunneling Protocol),即
2023-06-27

Linux下怎么配置JDK

这篇文章主要为大家展示了“Linux下怎么配置JDK”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“Linux下怎么配置JDK”这篇文章吧。JDK是 Java 语言的软件开发工具包,主要用于移动设
2023-06-28

Linux下怎么配置proftpd

这篇文章主要介绍了Linux下怎么配置proftpd,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。proftpd是一款开放源码的ftp服务器软件,它是原来世界范围使用最广泛的
2023-06-27

编程热搜

目录