1. MySQL installation A) MySQL installation: sudoapt-getinstallmysql-servermysql-clientB) start and stop the MySQL service: After MySQL is installed, MySQL is started; if you need to manually start or stop the service, perform the following operations: manually start the service: sudostartmysql manually stop the service: sudostopmysql when modifying
1. MySQL installation A) MySQL installation: sudo apt-get install mysql-server mysql-client B) start/stop MySQL service: After MySQL is installed, MySQL is started; if you need to manually start or stop the service, perform the following operations: manually start the service: sudo start mysql manual stop service: sudo stop mysql when modifying
1. Install MySQL
A) install MySQL: sudo apt-get install mysql-server mysql-client
B) start/stop the MySQL service:
After MySQL is installed, MySQL is started. to manually start or stop MySQL, perform the following operations:
Start the service manually: sudo start mysql
Stop Service manually: sudo stop mysql
When modifying mysql configurations, You need to manually restart the MySQL service.
Check whether the mysql process has been started:
?
# Ps-aux displays all current processes (including mysql and name users). grep mysql is used to find mysql processes. For specific usage, you can view ps and grep usage.
# Man ps; man grep
Or use:
?
sudo netstat -tap | grep mysql
|
Results of the two commands:
?
name@ThinkPad:~$ ps -aux | grep mysql
Warning: bad ps syntax, perhaps a bogus'-'? Seehttp://procps.sf.net/faq.html
mysql 25994 0.0 0.9 137800 18400 ? Ssl 10:18 0:10 /usr/sbin/mysqld
name 26543 0.0 0.1 8544 2320 pts/2 S+ 11:06 0:00mysql -u root -p
name 27068 0.0 0.1 8388 2064 pts/1 S+ 18:21 0:00mysql -u root -p
name 27917 0.0 0.0 5412 788 pts/3 S+ 21:45 0:00grep --color=auto mysql
name@ThinkPad:~$ sudo netstat -tap | grep mysql
tcp 0 0 localhost:mysql *:* LISTEN 25994/mysqld
|
C) MySQL configuration file structure:
The MySQL configuration file is my. cnf, which is located in/etc/my. cnf and/etc/mysql/my. cnf.
?
#
# The MySQL database server configuration file.
#
# You can copy this to one of:
# - "/etc/mysql/my.cnf"to set global options,
# - "~/.my.cnf"to set user-specific options.
#
# One can use all long options that the program supports.
# Run program with --helpto get a list of available options and with
# --print-defaults to see which it would actually understand and use.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html
# This will be passed toallmysql clients
# It has been reported that passwords should be enclosed with ticks/quotes
# escpecially if they contain"#"chars...
# Remember to edit /etc/mysql/debian.cnf when changing the socket location.
[client]
port = 3306
socket = /var/run/mysqld/mysqld.sock
# Here is entries for some specific programs
# The following values assume you have at least32M ram
# This was formally known as [safe_mysqld]. Both versions are currently parsed.
[mysqld_safe]
socket = /var/run/mysqld/mysqld.sock
nice = 0
[mysqld]
#
# * Basic Settings
#
#
# * IMPORTANT
# If you make changes to these settings and your system uses apparmor, you may
# also need to also adjust /etc/apparmor.d/usr.sbin.mysqld.
#
user = mysql
socket = /var/run/mysqld/mysqld.sock
port = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
skip-external-locking
#
# Instead of skip-networking thedefaultis now to listen only on
# localhost which is more compatible and is not less secure.
bind-address =127.0.0.1
#
# * Fine Tuning
#
key_buffer =16M
max_allowed_packet =16M
thread_stack =192K
thread_cache_size =8
# This replaces the startup script and checks MyISAM tables if needed
# the first time they are touched
myisam-recover = BACKUP
#max_connections =100
#table_cache =64
#thread_concurrency =10
#
# * Query Cache Configuration
#
query_cache_limit =1M
query_cache_size =16M
#
# * Logging and Replication
#
# Both location gets rotated by the cronjob.
# Be aware that this log type is a performance killer.
# As of 5.1you can enable the log at runtime!
#general_log_file = /var/log/mysql/mysql.log
#general_log =1
log_error = /var/log/mysql/error.log
# Here you can see queries with especially long duration
#log_slow_queries = /var/log/mysql/mysql-slow.log
#long_query_time =2
#log-queries-not-using-indexes
#
# The following can be used as easy to replay backup logs or for replication.
# note: if you are setting up a replication slave, see README.Debian about
# other settings you may need to change.
#server-id =1
#log_bin = /var/log/mysql/mysql-bin.log
expire_logs_days =10
max_binlog_size =100M
#binlog_do_db = include_database_name
#binlog_ignore_db = include_database_name
#
# * InnoDB
#
# InnoDB is enabled bydefaultwith a 10MB datafile in /var/lib/mysql/.
# Read the manual for more InnoDB related options. There are many!
#
# * Security Features
#
# Read the manual, too, if you want chroot!
# chroot = /var/lib/mysql/
#
# For generating SSL certificates I recommend the OpenSSL GUI"tinyca".
#
# ssl-ca=/etc/mysql/cacert.pem
# ssl-cert=/etc/mysql/server-cert.pem
# ssl-key=/etc/mysql/server-key.pem
[mysqldump]
quick
quote-names
max_allowed_packet =16M
[mysql]
#no-auto-rehash #fasterstart of mysql but no tab completition
[isamchk]
key_buffer =16M
#
# * IMPORTANT: Additional settings that can override those from this file!
# The files must end with'.cnf', otherwise they'll be ignored.
#
!includedir /etc/mysql/conf.d/
|
When MySQL is started, MySQL is started by reading the configuration file my. cnf and starting MySQL according to the file path:/var/run/mysqld. sock.
Datadir =/var/lib/mysql # indicates the location of the database. For example, if you create a database named mysql_first, the database files are stored in this directory.
Log_error =/var/log/mysql/error. log # mysql error file. If an error occurs while executing mysql, you can view the file.
D) enter MySQL
A password is generally required to access MySQL unless safe_mysql is used.
If no password is provided, the following error message is displayed:
?
ERROR 1045(28000): Access denied for user'name'@'localhost'(using password: NO)
|
This is because you have entered a password for installing MySQL and you need to provide a password;
Details:
?
name@ThinkPad:~$ sudo mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is40
Server version: 5.1.58-1ubuntu1(Ubuntu)
Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2license
Type 'help;'or'\h' for help. Type'\c' to clear the current input statement.
mysql>
|
Sudo mysql-u root-p # Here are several parameters: u indicates user, followed by a parameter; p indicates password, and Enter password is displayed below: Prompt
You can also directly provide the user and password (use --)
Sudo mysql -- user = root -- password = 123456
C) log out of MySQL
There are three main methods:
Mysql> exit
Bye
Mysql> quit
Bye
Mysql> # press Ctrl + D
2. uninstall MySQL
A) uninstall MySQL software
?
sudo apt-get autoremove --purge mysql-server-5.1
sudo apt-get remove mysql-server
sudo apt-get autoremove mysql-server
sudo apt-get remove mysql-common
|
Sudo apt-get autoremove -- purge mysql-server-5.1 # The mysql-server-5.1 in is the mysql-server version installed on the system
B) Clear other data
?
dpkg -l |grep ^rc|awk'{print $2}'| Sudo xargs dpkg-P
1. Delete mysql
1 sudo apt-get autoremove -- purge mysql-server-5.0
2 sudo apt-get remove mysql-server
3 sudo apt-get autoremove mysql-server
4 sudo apt-get remove mysql-common (very important)
In fact, some of the above are redundant. We recommend that you execute them in sequence.
Clean residual data
Dpkg-l | grep ^ rc | awk '{print $2}' | sudo xargs dpkg-P
2. Install mysql
1 sudo apt-get install mysql-server
2 sudo apt-get install mysql-client
3 sudo apt-get install php5-mysql (installation php5-mysql is to connect php and mysql)
Once the installation is complete, the MySQL server should be started automatically. You can run the following command at a terminal prompt to check whether the MySQL server is running:
1 sudo netstat-tap | grep mysql
When you run this command, you can see a line similar to the following:
Tcp 0 0 localhost. localdomain: mysql *: * LISTEN-
If the server cannot run properly, run the following command to start it:
1 sudo/etc/init. d/mysql restart
3. Enter mysql
$ Mysql-uroot-p administrator password
Configure the MySQL administrator password:
1 sudo mysqladmin-u root password newpassword