I am retiring a couple Linux servers, a web server and a database one.. I made a full database backup using the mysqldump command. Now I wanted to restore one, specific, database from this file on this Windows environment. This particular migration is of a network / WordPress Mu server. My MySQL server is installed on a Windows server, running IIS, and PHP.
Syntax:
open the Windows command prompt, navigate to your MySQL server installation, in my case this is at C:\MySQL\, then navigate to the bin folder where the exe mysql file resides.
mysql -u root -p --one-database destdbname < alldatabases.sql
Substitute dbname with the database name you want to restore, and alldatabases.sql with the name of your full DB backup.
If you would rather just extract the database dump of the single database from the --all-databases dump file, you can do this with sed using this command:
sed -n '/^-- Current Database: `dbname`/,/^-- Current Database: `/p' alldatabases.sql > output.sql
dbname is replaced with the database name of the database to extract, and alldatabases.sql is the name of your dump file. The result will be saved into the file output.sql.
Example from my environment:
C:\MySQL\bin>mysql -u root -p --one-database wpmu < C:\Users\administrator.A
D\Desktop\all_databases.sql
Enter password: *********
My personal Linux notes, a work in progress, shared online with the world. From intro to pro Linux Administration.
Wednesday, July 1, 2015
Monday, February 2, 2015
What the heck does SUDO mean in Linux?
sudo – short for “substitute user do” – is a command which allows users to run commands with other user’s rights (e.g. root).
Friday, November 1, 2013
Find Machine Name using an IP Address in Windows or Linux
Find Machine Name using an IP Address in Windows or Linux
C:\Users\Homer>nslookup 10.50.2.100
Server: windc.ad.simpson.org
Address: 10.50.2.70
*** windc.ad.simpospn.org can't find 10.50.2.100: Non-existent domain
C:\Users\Homer>nbtstat -a 10.50.2.100
Local Area Connection:
Node IpAddress: [10.12.4.29] Scope Id: []
Host not found.
MyLinux:/ # nslookup 10.50.2.100;
Server: 10.50.2.70
Address: 10.50.2.70#53
** server can't find 175.2.50.10.in-addr.arpa.: NXDOMAIN
MyLinux:/ # smbclient -L 10.50.2.100
Enter root's password:
Connection to 10.50.2.100 failed (Error NT_STATUS_CONNECTION_REFUSED)
MyLinux:/ # host 10.50.2.100
Host 175.2.50.10.in-addr.arpa. not found: 3(NXDOMAIN)
Find largest files
Type the following command at the shell prompt to find out top 10 largest file/directories:
If you want more human readable output try:
Where,
# du -a /var | sort -n -r | head -n 10If you want more human readable output try:
$ cd /path/to/some/where
$ du -hsx * | sort -rh | head -10Where,
- du command -h option : display sizes in human readable format (e.g., 1K, 234M, 2G).
- du command -s option : show only a total for each argument (summary).
- du command -x option : skip directories on different file systems.
- sort command -r option : reverse the result of comparisons.
- sort command -h option : compare human readable numbers. This is GNU sort specific option only.
- head command -10 OR -n 10 option : show the first 10 lines.
for i in G M K; do du -ah | grep [0-9]$i | sort -nr -k 1; done | head -n 11
This is also a good one ... here this returns the top 40:
find -type f -printf '%s %p\n'| sort -nr | head -40
also see: http://linuxcountry.blogspot.com/2013/05/find-and-sort-all-files-by-size-save.html
Wednesday, October 30, 2013
Using mysqldump - How to back up a MySQL database on Linux with the mysql dump command
You do not need to invoke the mysql command or log into your MySQL server..
From your linux shell command line type:
MyLinuxServer:/ # mysqldump -u root -p databaseName > databaseBackupFileName.sql;
You will be prompted to enter the password next "Enter password:"
Log into a MySQL server
Command:
MyLinuxServer:/ # mysql -u root -p
You will be prompted to enter the password "Enter password:" next
MyLinuxServer:/ # mysql -u root -p
You will be prompted to enter the password "Enter password:" next
Tuesday, October 22, 2013
Stop, Start, Restart, Status of MySQL server
I've tired many commands, I find these to work the best using the Sys-V init scripts located in
Start:
/etc/init.d.Start:
sudo /etc/init.d/mysql start
Stop:sudo /etc/init.d/mysql stop
Restart / reload configs:sudo /etc/init.d/mysql restart
Check run status:sudo /etc/init.d/mysql status
Wednesday, May 1, 2013
Find and sort all files by size, save results to a text file on a Linux system
Find and order all files by size, save the result to a text file on a Linux system
du -k | sort -nr | awk '
BEGIN {
split("KB,MB,GB,TB", Units, ",");
}
{
u = 1;
while ($1 >= 1024) {
$1 = $1 / 1024;
u += 1
}
$1 = sprintf("%.1f %s", $1, Units[u]);
print $0;
}
' > result_list_ordered.txt
du -k | sort -nr | awk '
BEGIN {
split("KB,MB,GB,TB", Units, ",");
}
{
u = 1;
while ($1 >= 1024) {
$1 = $1 / 1024;
u += 1
}
$1 = sprintf("%.1f %s", $1, Units[u]);
print $0;
}
' > result_list_ordered.txt
Find files by modification date, within a modified by date range on Linux
Find files modified within a date range
Use these commands
touch --date "2013-04-29" /tmp/start
touch --date "2013-05-1" /tmp/end
find -type f -newer /tmp/start -not -newer /tmp/end
Use these commands
touch --date "2013-04-29" /tmp/start
touch --date "2013-05-1" /tmp/end
find -type f -newer /tmp/start -not -newer /tmp/end
Labels:
Date,
Date Range,
Find,
Modified Date,
Search,
touch
Search or find all users on a Linux system
List all users on a Linux OS
Try one of these:
# cut -d: -f1 /etc/passwd
# cat /etc/passwd | cut -d ":" -f1
Got other ideas on how to do this? please leave a comment
Thanks!
Try one of these:
# cut -d: -f1 /etc/passwd
# cat /etc/passwd | cut -d ":" -f1
Got other ideas on how to do this? please leave a comment
Thanks!
Search files for a string in linux
Use grep
example, look for the text hsbc in the /srv/www/ location
# grep -r -l "hsbc" /srv/www/
example, look for the text hsbc in the /srv/www/ location
# grep -r -l "hsbc" /srv/www/
Apache web service wont start after restart, apache2 error "Address already in use"
If you stopped or restarted the apache2 server service and it failed to start this article should help.
You might type the command: rcapache2 start
You might get an error like this:
Starting httpd2 (prefork) (98)Address already in use: make_sock: could not bind to address [::]:80
(98)Address already in use: make_sock: could not bind to address 0.0.0.0:80
no listening sockets available, shutting down
Unable to open logs
startproc: exit status of parent of /usr/sbin/httpd2-prefork: 1 ... failed
Try this:
Run each of these commands
for i in `ps auwx | grep -i nobody | awk {'print $2'}`; do kill -9 $i; done
for i in `lsof -i :80 | grep http | awk {' print $2'}`; do kill -9 $i; done
for i in `lsof -i :80 | grep http | awk {' print $2'}`; do kill -9 $i; done
then run
service httpd restart
or run
rcapache2 start
Until next time
thanks
P.S. like anything else on this blog, the instructions are 'as is' and use art your own risk.
You might type the command: rcapache2 start
You might get an error like this:
Starting httpd2 (prefork) (98)Address already in use: make_sock: could not bind to address [::]:80
(98)Address already in use: make_sock: could not bind to address 0.0.0.0:80
no listening sockets available, shutting down
Unable to open logs
startproc: exit status of parent of /usr/sbin/httpd2-prefork: 1 ... failed
Try this:
Run each of these commands
for i in `ps auwx | grep -i nobody | awk {'print $2'}`; do kill -9 $i; done
for i in `lsof -i :80 | grep http | awk {' print $2'}`; do kill -9 $i; done
for i in `lsof -i :80 | grep http | awk {' print $2'}`; do kill -9 $i; done
then run
service httpd restart
or run
rcapache2 start
Until next time
thanks
P.S. like anything else on this blog, the instructions are 'as is' and use art your own risk.
Wednesday, March 6, 2013
Mysql ODBC connection to Linux Mysql database
If you have a database user that needs and ODBC connection to a mysql database, you create a user name and password, then before they can connect you need to add that user's computer IP address to linux to enable or allow access. By default, MySQL does not allow remote clients to connect to the MySQL database and your user is likely connecting remotely.
Use this code:
use mysql
GRANT ALL ON *.* to USERNAME @'10.30.1.2' IDENTIFIED BY 'PASSWORD';
FLUSH PRIVILEGES;
Replace the USERNAME and PASSWORD with your actual values.
Also, update firewall rules to make sure port# 3306 is open on the server that is running the mysql database.
remember, first you need to login to mysql
$ mysql -u root -p Enter password:
Labels:
connect,
database user,
MySQL,
ODBC,
remote connect,
user
Tuesday, February 19, 2013
Find the Size of Directory in Suse Linux
Try these
du -h ./
For the most part this works. If you have spaces in file/directory
names than you may get some errors, but I'm sure you can work around
those if needed:
ls -1drt *| xargs du -h --summarize
You could also try
du -hc --max-depth=1
This will give you all the directories in the current directory, and a total at the bottom. Play with the --max-depth to dig down further in the structure and get more fine-grained results.
You can run this with a pipe to grep "G" to do a quick search of folders that are large enough to be measured in gigabytes. It will pull any directories with a capital G in them, but there aren't many of those so it works for me.
du -hc --max-depth=1 | grep "G"
du -h ./
For the most part this works. If you have spaces in file/directory
names than you may get some errors, but I'm sure you can work around
those if needed:
ls -1drt *| xargs du -h --summarize
You could also try
du -hc --max-depth=1
This will give you all the directories in the current directory, and a total at the bottom. Play with the --max-depth to dig down further in the structure and get more fine-grained results.
You can run this with a pipe to grep "G" to do a quick search of folders that are large enough to be measured in gigabytes. It will pull any directories with a capital G in them, but there aren't many of those so it works for me.
du -hc --max-depth=1 | grep "G"
Friday, February 15, 2013
Where's the php.ini file
/etc/php.ini
Or here:
/etc/php/php.ini
/etc/php5/php.ini
Or here:
/usr/bin/php5/bin/php.ini
Anyway, you can always find any file named php.ini in this manner
find / -name php.ini
The simplest yet most powerful usage of the renowned find command. By its help I was able to locate the php.ini on my Ubuntu 9.04 Apache2 and PHP5:
/etc/php5/apache2/php.iniThursday, February 14, 2013
Show Processes Running on Linux, RAM process usage
ps command
Type the following ps command to display all running process:
Where,
# ps aux | lessWhere,
- -A: select all processes
- a: select all processes on a terminal, including those of other users
- x: select processes without controlling ttys
Task: see every process on the system
# ps -A
# ps -eTask: See every process except those running as root
# ps -U root -u root -NTask: See process run by user vivek
# ps -u vivekTask: top command
The top program provides a dynamic real-time view of a running system. Type the top at command prompt:
# topFree Disk Space / Disk usage on Linux
Q. How do I check free disk space in Linux or UNIX operating system? I've migrated from Windows NT to Linux and looking forward to get more information about free disk space.
A. Both Linux and UNIX offers two commands for checking out free disk space:
(a) df command : Report file system disk space usage
(b) du command : Estimate file space usage
df command examples - to check free disk space
Type df -h or df -k to list free disk space:
OR
$ df -hOR
$ df -klinuxServer:/ # df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda2 109038804 82892008 20610028 81% /
udev 3864264 92 3864172 1% /dev
/dev/sda3 10079572 5955024 3612484 63% /home
or you can run this command to get the file sizes at depth 1
# du -hc --max-depth=1
Thanks
Labels:
df,
disk space,
disk usage,
du,
free disk space,
space
Monday, January 28, 2013
Apache2 in Open SUSE - Start Stop Restart
To start, stop, or manipulate Apache on a running system, use the init script /usr/sbin/rcapache2. Thercapache2 command takes the following parameters:
status- Checks if Apache is started.
start- Starts Apache if it is not already running.
startssl- Starts Apache with SSL support if it is not already running. For more information about SSL support, refer toSection 20.6, “Setting Up a Secure Web Server with SSL”.
stop- Stops Apache by terminating the parent process.
restart- Stops and then restarts Apache. Starts the Web server if it was not running before.
try-restart- Stops then restarts Apache only if it is already running.
reloadorgraceful- Stops the Web server by advising all forked Apache processes to first finish their requests before shutting down. As each process dies, it is replaced by a newly started one, resulting in a complete “restart” of Apache.
Restart Apache 2 web server, enter:
# /etc/init.d/apache2 restartIf you are using Ubuntu use sudo:
$ sudo /etc/init.d/apache2 restartTo stop Apache 2 web server, enter:
# /etc/init.d/apache2 stop
OR
$ sudo /etc/init.d/apache2 stopTo start Apache 2 web server, enter:
# /etc/init.d/apache2 start
OR
$ sudo /etc/init.d/apache2 start
Monday, January 21, 2013
Samba
A caption from http://www.samba.org/samba/docs/SambaIntro.html
The NT Domain system deserves special mention because, until the release of Samba version 2, only Microsoft owned code to implement the NT Domain authentication protocols. With version 2, Samba introduced the first non-Microsoft-derived NT Domain authentication code. The eventual goal, of course, it to completely mimic a Windows NT Domain Controller.
The other two CIFS pieces, name resolution and browsing, are handled by
Name resolution takes two forms: broadcast and point-to-point. A machine may use either or both of these methods, depending upon its configuration. Broadcast resolution is the closest to the original NetBIOS mechanism. Basically, a client looking for a service named
The other type of name resolution involves the use of an NBNS (NetBIOS Name Service) server. (Microsoft called their NBNS implementation WINS, for Windows Internet Name Service, and that acronym is more commonly used today.) The NBNS works something like the wall of an old fashioned telephone booth. (Remember those?) Machines can leave their name and number (IP address) for others to see.
Clients on different subnets can all share the same NBNS server so, unlike broadcast, the point-to-point mechanism is not limited to the local LAN. In many ways the NBNS is similar to the DNS, but the NBNS name list is almost completely dynamic and there are few controls to ensure that only authorized clients can register names. Conflicts can, and do, occur fairly easily.
Finally, there's browsing. This is a whole 'nother kettle of worms, but Samba's
On a LAN, the participating computers hold an election to decide which of them will become the Local Master Browser (LMB). The "winner" then identifies itself by claiming a special NetBIOS name (in addition to any other names it may have). The LMBs job is to keep a list of available services, and it is this list that appears when you click on the Windows "Network Neighborhood" icon.
In addition to LMBs, there are Domain Master Browsers (DMBs). DMBs coordinate browse lists across NT Domains, even on routed networks. Using the NBNS, an LMB will locate its DMB to exchange and combine browse lists. Thus, the browse list is propagated to all hosts in the NT Domain. Unfortunately, the synchronization times are spread apart a bit. It can take more than an hour for a change on a remote subnet to appear in the Network Neighborhood.
The
What Samba Does
Samba consists of two key programs, plus a bunch of other stuff that we'll get to later. The two key programs aresmbd and
nmbd. Their job is to implement the four basic modern-day
CIFS services, which are:
- File & print services
- Authentication and Authorization
- Name resolution
- Service announcement (browsing)
smbd, the SMB Daemon. Smbd
also handles "share mode" and "user mode" authentication
and authorization. That is, you can protect shared file and print
services by requiring passwords. In share mode, the simplest and least
recommended scheme, a password can be assigned to a shared directory or
printer (simply called a "share"). This single password is then
given to everyone who is allowed to use the share. With user mode
authentication, each user has their own username and password and the
System Administrator can grant or deny access on an individual basis.
The Windows NT Domain system provides a further level of authentication
refinement for CIFS. The basic idea is that a user should only have to
log in once to have access to all of the authorized services on the
network. The NT Domain system handles this with an authentication server,
called a Domain Controller. An NT Domain (which should not be
confused with a Domain Name System (DNS)
Domain) is basically a group of machines which share the same Domain
Controller.
The NT Domain system deserves special mention because, until the release of Samba version 2, only Microsoft owned code to implement the NT Domain authentication protocols. With version 2, Samba introduced the first non-Microsoft-derived NT Domain authentication code. The eventual goal, of course, it to completely mimic a Windows NT Domain Controller.
The other two CIFS pieces, name resolution and browsing, are handled by
nmbd. These two services basically involve the
management and distribution of lists of NetBIOS names.
Name resolution takes two forms: broadcast and point-to-point. A machine may use either or both of these methods, depending upon its configuration. Broadcast resolution is the closest to the original NetBIOS mechanism. Basically, a client looking for a service named
Trillian will call out "Yo! Trillian! Where are
you?", and wait for the machine with that name to answer with
an IP address. This can generate a bit of broadcast traffic (a lot of
shouting in the streets), but it is restricted to the local LAN so it
doesn't cause too much trouble.
The other type of name resolution involves the use of an NBNS (NetBIOS Name Service) server. (Microsoft called their NBNS implementation WINS, for Windows Internet Name Service, and that acronym is more commonly used today.) The NBNS works something like the wall of an old fashioned telephone booth. (Remember those?) Machines can leave their name and number (IP address) for others to see.
Hi, I'm node Voomba. Call me for a good time! 192.168.100.101It works like this: The clients send their NetBIOS names & IP addresses to the NBNS server, which keeps the information in a simple database. When a client wants to talk to another client, it sends the other client's name to the NBNS server. If the name is on the list, the NBNS hands back an IP address. You've got the name, look up the number.
Clients on different subnets can all share the same NBNS server so, unlike broadcast, the point-to-point mechanism is not limited to the local LAN. In many ways the NBNS is similar to the DNS, but the NBNS name list is almost completely dynamic and there are few controls to ensure that only authorized clients can register names. Conflicts can, and do, occur fairly easily.
Finally, there's browsing. This is a whole 'nother kettle of worms, but Samba's
nmbd handles it anyway. This is not the web
browsing we know and love, but a browsable list of services (file and
print shares) offered by the computers on a network.
On a LAN, the participating computers hold an election to decide which of them will become the Local Master Browser (LMB). The "winner" then identifies itself by claiming a special NetBIOS name (in addition to any other names it may have). The LMBs job is to keep a list of available services, and it is this list that appears when you click on the Windows "Network Neighborhood" icon.
In addition to LMBs, there are Domain Master Browsers (DMBs). DMBs coordinate browse lists across NT Domains, even on routed networks. Using the NBNS, an LMB will locate its DMB to exchange and combine browse lists. Thus, the browse list is propagated to all hosts in the NT Domain. Unfortunately, the synchronization times are spread apart a bit. It can take more than an hour for a change on a remote subnet to appear in the Network Neighborhood.
Other Stuff
Samba comes with a variety of utilities. The most commonly used are:- smbclient
- A simple SMB client, with an interface similar to that of the FTP utility. It can be used from a Unix system to connect to a remote SMB share, transfer files, and send files to remote print shares (printers).
- nmblookup
- A NetBIOS name service client.
Nmblookupcan be used to find NetBIOS names on a network, lookup their IP addresses, and query a remote machine for the list of names the machine believes it ownes. - swat
- The Samba Web Administration
Tool.
Swatallows you to configure Samba remotely, using a web browser.
SMB Filesystems for Linux
One of the cool things that you can do with a Windows box is use an SMB file share as if it were a hard disk on your own machine. TheN: drive can look, smell, feel, and act like your own disk
space, but it's really disk space on some other computer somewhere else on
the network.
Linux systems can do this too, using the smbfs filesystem.
Built from Samba code, smbfs (which stands for SMB
Filesystem) allows Linux to map a remote SMB share into
its directory structure. So, for example, the /mnt/zarquon
directory might actually be an SMB share, yet you can read, write, edit,
delete, and copy the files in that directory just as you would local
files.
The
smbfs is nifty, but it only works with Linux. In
fact, it's not even part of the Samba suite. It is distributed with Samba
as a courtesy and convenience. A more general solution is the new
smbsh (SMB shell, which is still under
development at the time of this writing). This is a cool gadget. It is
run like a Unix shell, but it does some funky fiddling with calls to Unix
libraries. By intercepting these calls, smbsh can make it
look as though SMB shares are mounted. All of the read, write, etc.
operations are available to the smbsh user. Another feature
of smbsh is that it works on a per-user, per shell basis,
while mounting a filesystem is a system-wide operation. This allows for
much finer-grained access controls.
Setup and Management
Samba is configured using thesmb.conf file. This is a
simple text file designed to look a lot like those *.ini files used in
Windows. The goal, of course, is to give network administrators familiar
with Windows something comfortable to play with. Over time, though, the
number of things that can be configured in Samba has grown, and the
percentage of Network Admins willing to edit a Windows *.ini file has
shrunk. For some people, that makes managing the smb.conf
file a bit daunting.
Still, learning the ins and outs of smb.conf is a
worth-while penance. Each of the smb.conf variables has a
purpose, and a lot of fine tuning can be accomplished. The file structure
contents are fully documented, so as to give administrators a running head
start, and smb.conf can be manipulated using
swat, which at least makes it nicer to look at.
Subscribe to:
Posts (Atom)