MySQL Script – How to pass arguments
mysql -u root -e "set @variable:=xxx; source script.sql;"
mysql -u root -e "set @variable:=xxx; source script.sql;"
When all needed services from Amazon have been activated, we should install in our local machine the Amazon EC2 API Tools. The API tools serve as the client interface to the Amazon EC2 web service. Use these tools to register and launch instances, manipulate security groups, and more.
The downloaded file is just a folder with the utilities. We have to extract them wherever we want, but it would be nice if we were able to use them without writing the complete path to reach them. For that we have to include the path to the API Tools to the System Linux PATH variable in the following way:
export EC2_HOME=/usr/local/amazon/ec2-api-tools-1.3-57419 export PATH=$PATH:$EC2_HOME/bin export EC2_PRIVATE_KEY=/usr/local/amazon/keys/pk-blabla.pem export EC2_CERT=/usr/local/amazon/keys/cert-blabla.pem
We have to add these lines into the .bashrc file.
FTP Access.
If we want to have FTP access to the Amazon Server, we have to install a FTP server like vsftp and set up a new user for it.
If we use an already set up Wowza Amazon Server, we don’t need to do anything, because a FTP Server and a Wowza user are already set up.
Using Filezilla FTP Client.
If the case, we have to open the corresponding ports for the FTP connection. That can be performed using the Amazon AMI Tools in the following way:
ftp :> ec2-authorize default --region eu-west-1 -p 21 ssh :> ec2-authorize default --region eu-west-1 -p 22
Now we can use a normal FTP connection within the Filezilla client. The password is “password”. It can be changed using the command passwd wowza.
Creating an image
So, after we have configured our machine, we can save its status creating an image. Remember that when an AMI is shut down, all its configuration and saved data are lost. To avoid the tedious course of configuring the server, we can create images.
To create an image we have to type the following command:
ec2-bundle-vol -d mnt -k pk-asdfasdf.pem -c cert-adfasdf.pem -u 123-123-123 -r i386 -p name
With
ec2-bundle-vol -h
we can discover the meaning of the different options.
The next step is to upload the image to the S3 service. We can do that using the
ec2-upload-bundle
command.
For this image to become available, we have to register it in the AWS console:
ec2-register
Three main tasks for the basic configuration of MySQL in Linux:
1. Create the grant tables.
2. Start the server.
3. Verify server function.
For the first step we have to find the script mysql_install_db. In Ubuntu it is located in the folder /bin.
The initial account settings created with this script have no passwords associated with the accounts.
You can start the MySQL daemon with the following command in root mode:
cd /usr ; /usr/bin/mysqld_safe &
Remember to set a password for the MySQL root user.
To do so, start the server, then issue the following commands:
/usr/bin/mysqladmin -u root password ‘new-password’
/usr/bin/mysqladmin -u root -h name-of-your-laptop password ‘new-password’
See the manual for more instructions.
You can start the MySQL daemon with:
cd /usr ; /usr/bin/mysqld_safe &
You can test the MySQL daemon with mysql-test-run.pl, you’ll get output similar to that shown below:
cd mysql-test ; perl mysql-test-run.pl
./mysqladmin Ver 8.40 Distrib 4.0.22, for pc-linux on i686
Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL license
Server version 4.0.22
Protocol version 10
Connection Localhost via UNIX socket
UNIX socket /tmp/mysql.sock
Uptime: 45 sec
Threads: 1 Questions: 1 Slow Queries: 1 Opens: 6 Flush Tables: 1 Open Tables: 0 Queries per second avg: 0.022
Once the server is up and running, test it out! Put your SQL knowledge to work and ensure that you’re able to create tables and work with data. Don’t forget that one of your first tasks should be to add security to the default accounts created during the installation process.
En el paso de parámetros a funciones hay dos aproximaciones clásicas: el paso por valor y paso por referencia.
En el paso por valor se realiza una copia de los valores que se pasan, trabajando dentro de la función con la copia. Es por ello que cualquier cambio que sufran dentro, no repercute fuera de la función.
En el paso por referencia no se realiza dicha copia, por lo que las modificaciones de dentro de las funciones afectan a los parámetros y esos cambios permanecen al final de la función.
En Java el paso por parámetro es por valor, aunque los efectos son de paso por referencia cuando los argumentos son objetos. ¿cómo sucede eso? Pues es muy fácil, si una función tiene como argumento un tipo primitivo (int, float, etc…), en Java se realiza una copia para la función y cualquier cambio a dicho argumento no afecta a la variable original. Este paso de parámetros en Java está orientado a utilizar el valor de la variable para otros cálculos.
En el caso de los objetos es distinto. En realidad lo que sucede es que en Java siempre tenemos referencias a los objetos. Por eso al pasar a una función como argumento un objeto, pasamos la referencia al mismo, es decir, aunque se hace una copia para el paso por valor, como lo que se copia es una referencia, los cambios al objeto referenciado sí son visibles y afectan fuera de la función.
La única excepción es la clase String , cuyos objetos no son mutables. Cualquier modificación de un objeto String lleva aparejada la creación de una nueva instancia del objeto. Si deseamos el mismo comportamiento para el paso de parámetros del resto de objetos, tenemos que recurrir al objeto StringBuffer.
Comentarios originales:
Bueno, decir que la clase String es una excepción es algo equivocado. Efectivamente, la clase String es una clase inmutable, porque no se puede modificar el estado del objeto a través de ningún método del mismo. El objeto String inicializa su valor en el constructor y a partir de ese momento no cambia. Por lo tanto, como tu bien dices, cuando utilizamos el operador suma, ejemplo:
a = a + ” texto añadido.”;
Lo que se está haciendo es crear un nuevo objeto String con el resultado de concatenar el String a con en String ” texto añadido.”. Finalemente el operador de asignación hace que a deje de referenciar al antiguo String y apunte al objeto recién creado. Por supuesto, las otras referencias que puedan haber al antiguo a (en la función que llamo a esta) sigen apuntando al antiguo objeto.
Esto no es ninguna excepción, es simplemente el resultado lógico de la semantica de llamada de función de Java (paso por valor de la referencia) y de la semantica de las variables a objetos (las variables nunca son los objetos “en si” sino una referencia a los mismos).
Cualquier objeto inmutable reflejará este comportamiento.
Referencias:
http://www.error500.net/garbagecollector/java/paso_de_parmetros_a_funciones.html